$ (This is) .addClass ('why are you-not-worker'); doesn't work on waypoint?

I just tried dots today as it looks amazing,

However, I have a hard time trying to get everything to work,

first simple test, works great,

$('.parallax').waypoint(function() {
        alert('I work');
});

      

But when I use $ (this) it won't work for example.

$('.parallax').waypoint(function() {
        $(this).addClass('why-you-no-working');
});

      

you can see a sample from here -> http://jsfiddle.net/4D3bH/425/

the second block should have a black background color instead of blue, but for some reason its simple doesn't work,

If I use something like below it works fine, but

$('.parallax').waypoint(function() {
            $('.parallax').addClass('why-you-no-working');
});

      

It took almost three hours trying to get it to work but no luck,

Please, help:)

+3


source to share


1 answer


In this case, this

does not apply to DOMElement

. You can get a reference to DOMElement

, inside a callback via a propertythis.element

$('.parallax:nth-of-type(2)').waypoint(function() {        
    $(this.element).addClass('why-you-no-working');
},{offset: '1%'}); 

      



Example

+11


source







All Articles