开发者

jQuery .animate() and jamming image while moving

How to make sleek animation with jQuery of image moving right or left. It's working much better in Firefox than in Chrome or IE. Especially bad is jamming when duration is set to 2000 or more. Here is a sample of my demo page: http://pastehtml.com/view/1bj06p8.html

Code is:

$('img#image').mousemove(function(e){
        if (e.pageX > winWidth - moveAtX) {
            $('#status').html("go right");

            var left = { left: winWidth - imgWidth + 'px' }
            $('img#image').animate(
                left, 
                { queue:false, duration: "slow" }
            );
        }
        else if (e.pageX <= moveAtX) {
            $('#status').ht开发者_运维技巧ml("go left");

            var left = { left: '0px' };
            $("img#image").animate(
                left,
                { queue:false, duration: "slow" }
            );
        }
        else {
            $('#status').html(e.pageX +', '+ e.pageY + ' stop');
            $('img#image').stop();
        }
    });

Why isn't an image moving sleek?

Thanks!


The reason is that it continues making the call to mousemove, repeating many times the calls to animate.

You should limit the calls to these methods.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜