Same Waypoints on mutliple elements
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.
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")
}
});
@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.
Nice ! Thanks for the info.
// 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%' });