I am working on a website where I need to smoothly change between background images. Here is the JavaScript code I currently have:
var bg=[
'images/best.jpg',
'images/61182.jpg',
'images/bg.jpg'
];
$('._container-1').css('background-image','url('+bg[2]+')');
window.setInterval(
function(){
img=bg.shift();bg.push(img);
document.getElementsByClassName('_container-1')[0].style.backgroundImage='url('+img+')';
},
10000
);
However, I would like to make the image transitions slower and have attempted using jQuery's fadeIn/fadeOut methods like this:
window.setInterval(
function(){
img=bg.shift();
bg.push(img);
$('._container-1').fadeOut(600, function() {
$('._container-1').css('background-image','url('+img+')');
$('._container-1').fadeIn(600);
});
},
17000
);
The challenge I am facing is that there are buttons and text within the container that also change with the images. I want the text and buttons to remain in the front at all times while only the background fades in/out. I hope my explanation makes sense.
If anyone can provide assistance, it would be greatly appreciated.
nina_berlini