JSFiddle - React, Tailwind, and code Playground
by Ahmed Salama
HTML
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<div class="container">
<img src="http://wowslider.com/sliders/demo-6/data/images/canyon.jpg" alt="">
<div class="animateNextImage">
<div></div>
<div></div>
<div></div>
</div>
</div>
<button id="getNext">Get next</button>
CSS
.container{
position: relative;
}
.container img{
width: 100%;
}
.animateNextImage{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.animateNextImage div{
width: 33.3333%;
float:left;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
background-position: -100% 0%;
transition: background-position 0.5s ease;
}
.animateNextImage.active div:nth-child(1){
transition-delay: 0.4s;
background-position: 0% 0%;
}
.animateNextImage.active div:nth-child(2){
transition-delay: 0.2s;
background-position: 50% 0%;
}
.animateNextImage.active div:nth-child(3){
background-position: 100% 0%;
}
JavaScript
var nextActiveImg = "http://wowslider.com/sliders/demo-6/data/images/greenmountain.jpg";
$('#getNext').click(function(){
$(".animateNextImage div").css('background-image', "url('"+ nextActiveImg +"')");
$(".animateNextImage").addClass('active');
});