jQuery Waypoints Fire Once

user1214467 picture user1214467 · Apr 14, 2013 · Viewed 14.8k times · Source

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.

Answer

Jerome Braeken picture Jerome Braeken · Jun 8, 2015

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.