I'm trying to implement a slideshow on my site and having some difficulty. I opted to create a div to hold my photo(s) and use background-image to set the photo. All photos are named 1.jpg, 2.jpg ... 12.jpg.
Here's the div...
<div class="featureImg"></div>
...and the CSS:
#feature .featureImg {
[...some styling...]
background-image:url(../img/slideshow/1.jpg);
background-position:center;
background-repeat:no-repeat;
background-size:cover;
}
I want there to be an image on page load, then have it fade through the photos. Here's the jQuery I have right now, but the following does not work:
- They don't fade between each other
Here's the jQuery:
(function() {
var curImgId = 1;
var numberOfImages = 12; // Change this to the number of background images
window.setInterval(function() {
$('#feature .featureImg').css('background-image','url(/img/slideshow/' + curImgId + '.jpg)').fadeTo('slow', 1);
curImgId = (curImgId + 1) % numberOfImages;
}, 5 * 1000);
})();
Question: How can I fix this so that there is a photo on page load (like 1.jpg) and then fades from one photo to the next?