Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Waypoints Fire Once

I am using http://imakewebthings.com/jquery-waypoints and I need to do some action when the user scrolls down to the area with the class div1. However, I need it only fire once and not every time the user scrolls to that location. — only once

$('.div1').waypoint(function(direction) 
{
    alert(CARRY OUT MY ACTION);
});

This needs to only happen on the first scroll to that section — up or down.

like image 479
user1214467 Avatar asked Apr 14 '13 17:04

user1214467


2 Answers

triggerOnce() is replaced with destroy(). Just add this.destroy().

$('.div1').waypoint(function(direction){
    alert('CARRY OUT MY ACTION')
    this.destroy()
});

For more options check the API of Waypoints.

like image 85
Jerome Braeken Avatar answered Sep 19 '22 20:09

Jerome Braeken


If you pass a second parameter to the waypoint() function, you can include an object of configuration options. Setting the triggerOnce option to true will make the plugin behave the way you'd like.

$('.div1').waypoint(function(direction) 
{
    alert('CARRY OUT MY ACTION');
},  
{ 
    triggerOnce: true 
});
like image 44
George Hodgson Avatar answered Sep 18 '22 20:09

George Hodgson