Jump to content
Search Community

Getting target element in batch

callmegoon test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

I'm trying to figure out how to target the element within a batch process on scrollTrigger.  In my simple example, I have a script that is using scrollTrigger to look for all elements with a particular class.  When it comes into view, I'm toggling a class to change the color.  I want to be able to possibly run other functions on that element as well.  For example, I may want to add another class to it.  Or, I may want to delay it based on a data attribute. But, I can't seem to figure out how to get each target element.  I tried "this", I tried "this.target".  I tried $(this). 

 

For the sake of this question, let's just say I want to add another class to each element after it comes into view. I would have thought something like this would work, but I must be doing something wrong.

 

ScrollTrigger.batch(".animateOnLoad", {

    toggleClass: "inView",

    onEnter: function() {

        var element = this.target;

        setTimeout(function () {

            element.addClass('animationComplete');

        }, 2000);

    },

    once: true

});

 

Any tips here would be much appreciated! 

See the Pen jOrqgPx by callmegoon (@callmegoon) on CodePen

Link to comment
Share on other sites

  • Solution

 

Hey @callmegoon

 

I think it is only just 'target', but if you want to make use of it with jquery-functions later, you'd have to wrap it accordingly, like so

 

var element = $(target);

 

See the Pen 07089c5c7430d8acee308feb6919f65f by akapowl (@akapowl) on CodePen

 

Is this, what you're after?

Hope it helps.

 

Cheers,

Paul

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...