繁体   English   中英

jQuery自动滚动到底部(但在鼠标滚动时禁用)

[英]JQuery autoscroll to bottom (but disable on mousescrolling)

我按$ .get加载内容,并按照javascript-auto-scrolling“关注”新附加的数据。 现在,如果用户“手动滚动”,我想禁用自动滚动,但是以下滚动到底部的功能也触发了Jquery .scroll()函数-因此它禁用了itef。

if(self.testelem.hasClass("active")){
    $(document).scrollTop($(document).height());
}

如何接收鼠标滚轮事件或阻止scrollTop触发.scroll()函数? 我还尝试将超时设置为在scrollTop工作时阻止,但这不是一个很好的解决方案,并且有一些缺点。

有什么建议么?

编辑:我当前的代码:

我使用按钮#stb(滚动到底部)和类.active来关闭/打开它。

$.get("url", function(data){
    //do something          
    if(self.testelem.hasClass("active")){
        $(document).scrollTop($(document).height());
    }
}); 

$(document).scroll(function(){
    jQuery('html,body').queue([]).stop();  //try this
    //$("#stb").parent().removeClass("active");
});

ps:是的,我知道。 有一些非常相似的问题。 我读过它们,但是它们在要点上有所不同。

要在用户中断中间滚动时停止scrollTo事件,请尝试以下操作:

$(document).scroll(function(){
    jQuery('html,body').queue([]).stop();  //try this
    //jQuery.scrollTo.window().queue([]).stop(); //failing that try this
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM