开发者

How can I smooth out this on mouseover animation?

开发者 https://www.devze.com 2023-04-02 07:51 出处:网络
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 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()开发者_如何学JAVA 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

http://jsfiddle.net/cbXh5/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号