我需要重新bind()
scroll()
至$(window)
再次使用unbind()
后阻止 div self 复制 - (#mystat-1)
。我已经尝试过$(window).bind('scroll');
但它不起作用。谢谢!
$(window).scroll(function() {
if ($("#moreSection").visible(true)) {
doActionAndStopScript();
}
});
function doActionAndStopScript() {
$('#myStat-1').circliful() // now it will fire once
$(window).unbind('scroll');
}
最佳答案
对于这种情况,我建议您使用 event.namespace 。我还建议您使用$.fn.on()
和 $.fn.off()
代码是不言自明的。
//Declare a event hanlder
function scrollHandler(){
if ($("#moreSection").visible(true)){
doActionAndStopScript();
//Bind event
$(window).on('scroll.test', scrollHandler);
}
}
function doActionAndStopScript(){
// now it will fire once
$('#myStat-1').circliful();
//Unbind it
$(window).off('scroll.test');
}
//Bind event
$(window).on('scroll.test', scrollHandler);
关于jquery - 解除绑定(bind)后如何重新绑定(bind)jQuery窗口滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669557/