I'm trying to cycle between various background images for a website I'm building. Everything works as intended on Chrome, but on firefox and edge I'm getting some frustrating errors. I coded a small script that changes the background-image of a div element every 8 seconds, but after the first interval the screen goes blank on firefox and edge. When I check the console, it says the browser failed to load the image, yet it points to the correct image.
I've tried using webkits and that didn't work either.
script for changing backgrounds:
var images = [
'url(../photos/pancake.jpg)',
'url(../photos/waffles.jpg)',
'url(../photos/eggs.jpg)',
'url(../photos/sandwich.jpg)'
]
var counter = 0;
function changeBg() {
document.querySelector('.bgImg').style.backgroundImage = images[counter];
counter++;
if (counter === images.length) {
counter = 0;
}
}
setInterval(changeBg, 8000);
CSS:
.bgImg {
background-image: url(../photos/pancake.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
min-height: 100%;
min-width: 100%;
position: absolute;
transition: all 0.8s;
}