10

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.

Marc
  • 4,661
  • 3
  • 40
  • 62
user1214467
  • 111
  • 1
  • 1
  • 4

4 Answers4

33

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.

Jerome Braeken
  • 483
  • 5
  • 8
14

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 
});
fedosov
  • 1,989
  • 15
  • 26
George Hodgson
  • 471
  • 2
  • 12
1

In the new API, it seems that there is no triggerOnce option anymore, but still can be used the waypoint.disable() method after the first call

Seer
  • 739
  • 4
  • 22
1

The answer is to use this.destroy() at the end of your handler function. Here is an example that will work:

$('.div1').waypoint(function(direction){

    handler: function(direction) {

        alert('CARRY OUT MY ACTION');

        this.destroy();

    }

});

Also see the waypoint.destroy() documentation.

Marc
  • 4,661
  • 3
  • 40
  • 62