jQuery动画更流畅?

时间:2011-11-01 08:52:44

标签: jquery jquery-animate setinterval smooth motion

问题演变为

  1. 这个随机浮动脚本只允许步进移动 首先是左边然后是顶部,但完美的是两者之间
  2. 这是不顺利的
  3. 我尝试使用缓动插件aslo

    代码在这里:

    function ran(min, max)
    {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    function moveIt()
    {
        $(".circle").each(function() {
            x = ran(-3, 3);
            y = ran(-3, 3);
            pos = $(this).position();
            nowX = pos.left + x;
            nowY = pos.top + y;
            $(this).animate({"left": nowX}, {queue:false, duration:400, easing: 'linear'});
            $(this).animate({"top":  nowY}, {queue:false, duration:400, easing: 'linear'});
        });
    }
    setInterval(moveIt, 400);
    

1 个答案:

答案 0 :(得分:2)

使用以下内容更新了您的功能。

1)将您的2 animate()次调用合并为1

2)使用setInterval()自己的animate()回调替换success以递归调用。

3)使用setInterval()方法替换delay()

4)尝试通过减少每个循环之间的延迟来“平滑”动画。 (这是你设定的400)

http://jsfiddle.net/6kxts/

相关问题