开发者

How can I smooth out this on mouseover animation?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜