I have a bunch of blocks that I'm trying to have move along a square 'track', like a train.
var itemLoop = function(){
$("li").each(function(getLeft, getTop) {
getLeft = parseInt($(this).css('left'));
getTop = parseInt($(this).css('top'));
if (getTop > 0 && getLeft < 5) {
$(this).css('top', (getTop - 5 ) + "px");
} else if (getTop > 140) {
$(this).css('left', (getLeft - 5) + "px");
} else if (getLeft > 140) {
$(this).css('top', (getTop + 5 ) + "px");
} else {
$(this).css('left', (getLeft + 5 ) + "px");
}
});
}
setInterval(itemLoop, 100);
However, for the above, the blocks don't snake around the corners, but stay stuck together.
I thought maybe it was because the same getTop/Left value is being used for all the lis, but I'm not sure how else I could script this.