0

问题围绕

  1. 这个随机浮动脚本只允许首先向左然后向顶部进行步进移动,但在完美情况下它会在两者之间
  2. 它不够光滑

我也尝试过缓动插件

代码在这里:

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);
4

1 回答 1

2

用下面更新了你的功能。

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

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

3)更换setInterval()使用delay()方法。

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

http://jsfiddle.net/6kxts/

于 2011-11-01T09:22:57.497 回答