[英]JQuery autoscroll to bottom (but disable on mousescrolling)
I load my content per $.get and "follow" the new appended data per javascript-auto-scrolling. 我按$ .get加载内容,并按照javascript-auto-scrolling“关注”新附加的数据。 Now I want to disable autoscrolling if the user "scrolls manually", but the following scroll-to-bottom function also triggers the Jquery .scroll()-function - so it disables itsef. 现在,如果用户“手动滚动”,我想禁用自动滚动,但是以下滚动到底部的功能也触发了Jquery .scroll()函数-因此它禁用了itef。
if(self.testelem.hasClass("active")){
$(document).scrollTop($(document).height());
}
How can I receive a mouse-wheel event or prevent scrollTop to trigger the .scroll()-function? 如何接收鼠标滚轮事件或阻止scrollTop触发.scroll()函数? I also tried to set a Timeout to block while scrollTop is working, but this isn't a great solution and has a few drawbacks. 我还尝试将超时设置为在scrollTop工作时阻止,但这不是一个很好的解决方案,并且有一些缺点。
Any suggestions? 有什么建议么?
EDIT : My current code: 编辑:我当前的代码:
I use the button #stb (scroll to bottom) and the class .active to to turn it off/on. 我使用按钮#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: Yes, I know. ps:是的,我知道。 There are a few quite similar questions. 有一些非常相似的问题。 I read them, but they differ in important points. 我读过它们,但是它们在要点上有所不同。
To stop a scrollTo
event on user-interruption mid-scroll try this: 要在用户中断中间滚动时停止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.