I have the code below in my wordpress site, its allowing a set of images to rotate as background images on a div, works well, but its not quite what I need.
The fade on this is quite harsh, what I think I would prefer is for the images to fade in and out, rather than an image disappearing to white and then the next one appears, so they fade in and out to make it more smooth.
(function($){//begin closure
//variable to keep the index count
var count = 0;
//Time in milliseconds(currently set to 4 seconds)for the setInterval Function
//
var milliseconds = 8000;
//Time in milliseconds for the animated transition.
var transitionTime = 3500;
//selects an element with an id of target
//use .className if you want to select an element by a className
var selector = "#homePageHeaderBgImage";
setInterval(function(){
//Array to store image urls(replace with the urls of your images)
var images= ["http://www.accend4web.co.uk/DandG/wp-content/uploads/2019/02/Test-Home-Large-Header.jpg",
"http://www.accend4web.co.uk/DandG/wp-content/uploads/2019/02/Test-Home-Large-Header.jpg"];
//create a new image
var tempImage = new Image();
//add the image src
tempImage.src = images[count];
//on load event for the image object
$(tempImage).on("load",function(){//begin event
//set the opacity of the element to zero(transparent),
//animate it to opaque by setting its opacity to 1
$(selector).css("opacity","0")
.animate({ opacity: 1, specialEasing: {width: "linear", height: "easeOutBounce"} }, { duration: transitionTime });
//change the background image
$(selector).css("background-image", "url(" + tempImage.src +")");
});//end event
//If the count is less than the image array length - 1,
//Explanation: Array indexes start at 0 so you will need to subtract
//1 to match array index. If you do not subract one then the code will
//try and load images[2] which doesn't exist.
if(count < images.length - 1){
//increment the count
count++;
}
else{
//reset count to 0 when the the last index is reached.
count = 0;
}
},milliseconds);//<-- pass in the interval time to execute the code
})(jQuery);//end closure