2011-11-01 106 views
0

问题演变各地jQuery动画更平滑吗?

  1. 这个随机浮动脚本只允许作步进移动 作为第一至左边,然后到顶部,但在完善这将是两个
  2. 它并不顺利足够多间

我试图缓和插件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); 
+0

因此,我们知道你的问题,现在什么是你的** **的问题? – Bojangles

+0

如何摆脱zigg-zagg运动......这是微小的...但明显 –

+0

可能重复的[平滑Jquery动画](http://stackoverflow.com/questions/6323138/smoother-jquery-动画) – davidcondrey

回答

2

用以下更新了您的功能。

1)合并的2 animate()调用到1

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

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

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

http://jsfiddle.net/6kxts/