为什么我的动画在恢复后变得非常慢?
我有一个 jQuery 动画,它可以对容器上的“scrollLeft”进行动画处理,以产生一种“选取框”效果。
我已将其设置为当鼠标悬停在容器上时它会停止动画,而当鼠标离开时它会恢复。
$(banksContainer).mouseover(function() {
$(banksContainer).stop(false);
});
$(banksContainer).mouseleave(function() {
startAnimation();
});
每当我将鼠标移到动画上然后移开动画时,它都会以极慢的速度恢复,但在一分钟左右后逐渐加快。
为什么会出现这种情况以及可以解决吗?
附言。 这是所要求的 startAnimation 函数:
// recursive function - represents one cycle of the marquee
function startAnimation() {
$(banksContainer).animate(
{ scrollLeft: scrollLeftEnd },
35000,
"linear",
function() {
$(this)[0].scrollLeft = scrollLeftHome;
startAnimation();
}
);
}
I have a jQuery animation that animates the 'scrollLeft' on a container to produce a kind of 'marquee' effect.
I have it set up so on mouse-over of the container it stops the animation, and on mouse-leave, it resumes.
$(banksContainer).mouseover(function() {
$(banksContainer).stop(false);
});
$(banksContainer).mouseleave(function() {
startAnimation();
});
Whenever I move the mouse over the animation then off the animation, it resumes at an extremely slow speed, but gradually picks up after a minute or so.
Why is this happening and can it be resolved?
PS. Here's the startAnimation function as requested:
// recursive function - represents one cycle of the marquee
function startAnimation() {
$(banksContainer).animate(
{ scrollLeft: scrollLeftEnd },
35000,
"linear",
function() {
$(this)[0].scrollLeft = scrollLeftHome;
startAnimation();
}
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为当您恢复动画时,移动距离已缩短,但时间仍为 35 秒。 因为速度=距离/时间,所以速度会很慢。
我认为你应该根据剩余距离设置时间。 即 35000 * 剩余距离 / 总距离。
像这样的东西吗?
That's probably because when you resume the animation, the distance to cover has reduced but the time remains at 35 seconds. since speed = distance / time, it would be slow.
I think you should set the time proportionate to the distance remaining. That would be 35000 * distance remaining / total distance.
Something like this?