I am trying to change different backgrounds for a div loop going through an array of images and timing it every 5 seconds.
here is my code:
function changeBG(){
var array = ["test.jpg", "test2.jpg", "test3.jpg",];
for ( var i=0, len=array.length; i<len; ++i){
$('.round-mask').css('background-image', 'url("images/work/'+array[i]+'")');
}
}
window.setInterval(changeBG(), 5000);
This does not work, I see that it is a loop, but I always get the third image.
Any idea?
Thanks in advance.
Mauro
source
share