快速提问。
试图为我的网站制作一个可悬停的滚动控件。当您将鼠标悬停在按钮上而不是单击它时,我希望页面滚动。我让它大部分工作,但它似乎有点小故障,主要是因为悬停事件不断触发动画方法。我想知道是否有更干净的方法来触发它。以下是我到目前为止的代码。
$("#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
});
谢谢你的帮助