Reputation: 478
problem evolves around
I tried with easing plugin aslo
code is here:
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);
Upvotes: 0
Views: 2104
Reputation: 4433
Updated your function with below.
1) Merge your 2 animate()
invocation into 1
2) Replace the setInterval()
using animate()
's own success
callback to invoke recursively.
3) Replace the setInterval()
using delay()
method.
4) Try to 'smoothen' the animation by decreasing the delay between each loop. (Which was 400 set by you)
Upvotes: 2