如何在鼠标悬停动画上平滑此效果?
我有一个 div,它根据鼠标的位置向左和向右设置动画,但它太不稳定了(尤其是在 IE 中)。
我很确定它与 mousemove 函数内部的 .stop()
有关,因此在几秒钟内被调用数百次,但这是我能得到的最好的结果。我希望它是一个干净、连续的动画...
jQuery
$('#videoThumbContainer').mousemove(function(e){
var offset = $(this).offset(),
containerWidth = $(this).width(),
runnerWidth = $('#videoThumbRunner').width(),
relativeX = e.pageX - offset.left,
difference = parseInt(containerWidth - runnerWidth),
position = (relativeX / containerWidth) * difference;
if (runnerWidth > containerWidth) {
$('#videoThumbRunner').stop().animate({left: position}, 50, 'linear');
}
});
演示
I have a div that it animating left and right based on the mouse's position, but it's too jittery (especially in IE).
I'm pretty sure it has something to do with a .stop()
being inside the mousemove function, thus being called hundreds of times in seconds, but it's the best I can get it. I want it to be a clean, continuous animation...
jQuery
$('#videoThumbContainer').mousemove(function(e){
var offset = $(this).offset(),
containerWidth = $(this).width(),
runnerWidth = $('#videoThumbRunner').width(),
relativeX = e.pageX - offset.left,
difference = parseInt(containerWidth - runnerWidth),
position = (relativeX / containerWidth) * difference;
if (runnerWidth > containerWidth) {
$('#videoThumbRunner').stop().animate({left: position}, 50, 'linear');
}
});
Demo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论