jquery - 解除绑定(bind)后如何重新绑定(bind)jQuery窗口滚动?

标签 jquery scroll bind unbind

我需要重新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/

相关文章:

HTML - 启用表格单元格内的滚动

javascript - 如何捕获 "blur"或 "keypress"在 javascript jquery 中输入 13 - 或者两者都不是

javascript - 如何更新javascript对象

javascript - jQuery点击改变颜色

jquery 无法从 perl 获取响应

jquery - 无限卷轴在 Tumblr 上用砖石打破

c# - 如何在更新面板 Asp.net C# 中保持滚动位置?

C绑定(bind)到指定的TCP端口

r - 如何使用基本 R 绑定(bind)列表中的每个第 n 个元素?

jquery - 自动滑动 jQuery jCarousel Lite 不工作