【发布时间】:2012-01-15 20:33:47
【问题描述】:
我正在使用来自 SO 用户的这段代码:
$("#rightSubMenu").mousemove(function(e){
console.log('executed');
var h = $('#rightSubMenuScroller').height()+13;
var offset = $($(this)).offset();
var position = (e.pageY-offset.top)/$(this).height();
if(position<0.33) {
$(this).stop().animate({ scrollTop: 0 }, 1000);
}
else if(position>0.66) {
$(this).stop().animate({ scrollTop: h }, 2000);
}
else
{
$(this).stop();
}
});
它的作用基本上是移动#rightSubMenuScroller,它位于#rightSubMenu 内,每当您将鼠标悬停在rightSubMenu 上时。问题在于,随着每个像素的移动,它会再次执行整个函数,从而导致动画滞后。
当我激活滚动并将鼠标从元素上移开时,动画效果很好。
我需要修复代码以使其不会滞后。有什么想法吗?
【问题讨论】:
标签: jquery