I have a series of animation co-ordinates stacked inside a loop. I want to run ALL co-ordinates over a certain period and when it finishes going through all it must start from the top and run through them again.
The loop works, but it doesn't start from the first co-ordinates ('top':'+=50' and 'left':'+=300') when it goes through the loop.
var port = $('span.view-port'),
yoyoDuration = 100,
run = setInterval( function (){
port.animate({
'top': '+=50',
'left': '+=300'
}, {duration: 1500}) /* -- first co-ordinates -- */
.animate({
'top': '+=80',
'left': '-=300'
}, {duration: 1500})
.animate({
'left': '+=300',
}, {duration: 2500})
.animate({
'top': '-=80',
'left': '-=300'
}, {duration: 2500})
.animate({
'top': '+=150',
'left': '+=300'
}, {duration: 2500})
.animate({
'top': '+=50',
'left': '-=300'
}, {duration: 2500}) /* -- last co-ordinates -- */
}, 500);
setTimeout(function () {
}, yoyoDuration);
.css(). Since you're using+=and-=, those are relative to the current location. So, to make the current location what you want at the start of each iteration, you have to make the numbers do that.