jQuery Waypoints Fire Once

ぐ巨炮叔叔 提交于 2019-12-05 04:48:53

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.

George Hodgson

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 
});

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!