快速提问。
尝试为我的网站制作一个可悬停的滚动控件。当您将鼠标悬停在按钮上而不是单击它时,我希望页面滚动。我让它大部分时间都在工作,但它似乎有点小故障,主要是因为悬停事件不断触发动画方法。我想知道是否有更干净的方式来触发它。下面是我到目前为止的代码。
$("#goUp").hover(function () {
var curpos= $('body').scrollTop();
$("body").animate({scrollTop: curpos- 200}, 800);
}, function () {
// I want to stop the animation here when they mouse out
});
$("#goDown").hover(function () {
var curpos= $('body').scrollTop();
$("body").animate({scrollTop: curpos+ 200}, 800);
}, function () {
// I want to stop the animation here when they mouse out
});
感谢您的帮助
最佳答案
使用以下命令停止动画。
$("body").stop()
关于Jquery 向上滚动悬停停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13992763/