JSFiddle - React, Tailwind, and code Playground
HTML
<div class="transparency"></div>
<!-- create the background of images -->
<div id="slideshow">
<img class="active" src="img/landing-image-1.jpg" alt="Slide Show Image - 1" />
<img src="img/landing-image-2.jpg" alt="Slide Show Image - 2" />
<img src="img/landing-image-3.jpg" alt="Slide Show Image - 2" />
<img src="img/landing-image-4.jpg" alt="Slide Show Image - 2" />
<img src- "img/landing-image-5.jpg" alt="Slide Show Image - 2" />
</div>
CSS
#slideshow {
position: relative;
height: 350px;
z-index: -1;
}
#slideshow IMG {
position: absolute;
top: 0;
left: 0;
z-index: 8;
opacity: 0.0;
}
#slideshow IMG.active {
z-index: 10;
opacity: 1.0;
}
#slideshow IMG.last-active {
z-index: 9;
}
#slideshow img {
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
}
@media screen and (max-width: 1024px) {
img.bg {
left: 50%;
margin-left: -512px;
}
}
JavaScript
//switch the landing page background images
function slideSwitch() {
//set variable active
var $active = $('#slideshow IMG.active');
//check if attribute active exists
if ($active.length == 0) $active = $('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
//throw images in random order
var $sibs = $active.siblings();
var rndNum = Math.floor(Math.random() * $sibs.length);
var $next = $($sibs[rndNum]);
$active.addClass('last-active');
$next.css({
opacity: 0.0
})
.addClass('active')
.animate({
opacity: 1.0
}, 1000, function () {
$active.removeClass('active last-active');
});
}
$(function () {
setInterval("slideSwitch()", 1000);
});