Try using Animate:
function animateCircle(id, speed, radius, startx, starty, phi) { if (!phi) { phi = 0 }; var int = 2 * (Math.PI) / speed; phi = (phi >= 2 * (Math.PI)) ? 0 : (phi + int); var $m = startx - radius * Math.cos(phi); var $n = starty - radius * Math.sin(phi); $("#friends").animate({ marginLeft: $m + 'px', marginTop: $n + 'px' }, 1, function() { animateCircle.call(this, id, speed, radius, startx, starty, phi) } ); };
You can call a function for any div as follows:
animateCircle('#friends', 100, 100, 400, 250);
DEMO : http://jsfiddle.net/W69s6/18/
DEMO 2 : http://jsfiddle.net/W69s6/34/
Adapted from here .
Jivings
source share