waypoints icon indicating copy to clipboard operation
waypoints copied to clipboard

Same Waypoints on mutliple elements

Open regisphilibert opened this issue 11 years ago • 4 comments

Hey there, and thanks for this awesome plugin ;)

I could not find in the doc a proper exemple as to how access $(this) inside a simple jquery waypoint call on mutliple elements.

$('.waypoint-slide').waypoint(function(direction){
  console.log($(this).find('img').attr('src'));
});

logs undefined each time one of the .waypoint-slide element is triggered.

$('.waypoint-slide').waypoint(function(direction){
  $(this).addClass('-enter-anim');
});

will add the .-enter-anim class on every .waypoint-slide element whenever the first one is triggered by waypoint.

These two pieces of code used to work in jQuery Waypoints - v1.0.2 back when it was jQuery only and I couldn't find in a the doc, the way to make it work now.

For exemple :

var waypoint = new Waypoint({
  element: $('.waypoint-slide'),
  handler: function(direction) {
  console.log(this.element.find('img').attr('src'));
  this.element.addClass('-enter-anim');
  }
});

only log the first element's img[src] but adds the class to EVERY elements.

I-am-a-bit-confused :/

Cheers.

regisphilibert avatar Jul 06 '15 18:07 regisphilibert

I am using animate.css and adding a class to the element works like this:

$('.fade-in-up').waypoint({
    handler: function() {
        $(this.element).addClass("visible animated fadeInUp")
    }
});

machwatt avatar Jul 10 '15 07:07 machwatt

@regisphilibert As of Waypoints 3.0.0 you get access to the DOM element through this.element, which in the old jQuery-only world was plain ol' this.

imakewebthings avatar Aug 13 '15 05:08 imakewebthings

Nice ! Thanks for the info.

regisphilibert avatar Aug 13 '15 12:08 regisphilibert

// Waypoints with animate.css just add a class "fade-in-right" to which you want to add animations to multiple elements

    $('.fade-in-right').css('opacity', 0);
    $('.fade-in-right').waypoint(function() {
        $('.fade-in-right').addClass('fadeInRight');
    }, { offset: '70%' });
  
    $('.fade-in-left').css('opacity', 0);
    $('.fade-in-left').waypoint(function() {
        $('.fade-in-left').addClass('fadeInLeft');
    }, { offset: '70%' });

    $('.fade-in-up').css('opacity', 0);
    $('.fade-in-up').waypoint(function() {
        $('.fade-in-up').addClass('fadeInUp');
    }, { offset: '70%' });

    $('.fade-in-up').css('opacity', 0);
    $('.fade-in-up').waypoint(function() {
        $('.fade-in-up').addClass('fadeInUp');
    }, { offset: '70%' });

anonewb avatar Nov 15 '18 11:11 anonewb