可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Doing some quick work using http://imakewebthings.com/jquery-waypoints I need to do some action when the user scrolls down to area class div1 but need it only to be done 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.
回答1:
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.
回答2:
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 });
回答3:
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