I am trying to make a changing background. So what I am trying to do is using SetInterval to change my background but whenever it changes, it leaves a white background and then turn to the image like I intend. Any advices on how to fix it?
My code:
var image = new Array();
image.push("url('./1.png')");
image.push("url('./2.png')");
image.push("url('./3.png')");
image.push("url('./4.png')");
image.push("url('./5.png')");
var imagenum = 0;
function changeBackground () {
imagenum++;
if (imagenum==5) {
imagenum = 0;
}
document.getElementById("bodydiv").style.backgroundImage = image[imagenum];
}
function init () {
setInterval(function () {changeBackground()},1000);
}
Bonus: If I set the setInterval a little bit lower, I will have the whole blank site. It works perfectly due to the code, but the flash really irritates me. Can anyone help me with it?