So I'm making this slideshow on my website. Right now it moves all pictures outside the screen to the left, appends the first item to the end of the container and then repeats. The thing is I had to set a timer bigger than the animation time or else it would every other time animate the wrong element. How can I make it repeat when the appendTo function is complete without having a delay?
What it looks like: https://gyazo.com/04b427117ee9d01f65fcdba790ec0730
Javascript:
$(function(){
setInterval(function(){
var p = $(".photo-grid-slideshow .photo-crop").css('width');
$(".photo-grid-slideshow .photo-crop:first-of-type").animate({marginLeft: '-=' + p}, 3000, "linear", function(){
$(this).css("margin-left", 0).appendTo('.photo-grid-slideshow');
})
}, 3500);
});