I have this script that moves a box around the screen and the loops the second part of the movement. I have altered the code to drop another three boxes (4 in total) into the animation so the boxes follow each other around the screen.
I want it to work exactly like it does, but I'm sure there's a much better way of doing this:
Here's a js fiddle: http://jsfiddle.net/NF6LU/
JS
function animateNode() {
$('.node').animate({top: '425px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node2').animate({top: '425px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node3').animate({top: '425px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node4').animate({top: '425px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node').animate({marginLeft: '-284px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node2').animate({marginLeft: '-284px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node3').animate({marginLeft: '-284px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node4').animate({marginLeft: '-284px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node').animate({top: '157px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node2').animate({top: '157px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node3').animate({top: '157px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node4').animate({top: '157px'}, { duration: 1800, easing : 'linear', queue: true });
$('.node').animate({marginLeft: '264px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node2').animate({marginLeft: '264px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node3').animate({marginLeft: '264px'}, { duration: 2500, easing : 'linear', queue: true });
$('.node4').animate({marginLeft: '264px'}, { duration: 2500, easing : 'linear', queue: true });
}
$('.node').delay(1500).animate({top: '157px'}, { duration: 1000, easing : 'linear', queue: true });
$('.node2').delay(3000).animate({top: '157px'}, { duration: 1000, easing : 'linear', queue: true });
$('.node3').delay(4500).animate({top: '157px'}, { duration: 1000, easing : 'linear', queue: true });
$('.node4').delay(6000).animate({top: '157px'}, { duration: 1000, easing : 'linear', queue: true });
$('.node').animate({marginLeft: '264px'}, { duration: 1500, easing : 'linear', queue: true });
$('.node2').animate({marginLeft: '264px'}, { duration: 1500, easing : 'linear', queue: true });
$('.node3').animate({marginLeft: '264px'}, { duration: 1500, easing : 'linear', queue: true });
$('.node4').animate({marginLeft: '264px'}, { duration: 1500, easing : 'linear', queue: true });
$(function(){
animateNode();
setInterval(animateNode, 2000);
});
HTML
<span class="node"></span>
<span class="node2"></span>
<span class="node3"></span>
<span class="node4"></span>
CSS
span.node, span.node2, span.node3, span.node4{
height: 16px;
width: 16px;
background-color: black;
position: absolute;
top: 60px;
left: 50%;
margin-left: -9px;
}