I am showing and hiding images depending on a button click by changing the src like this...
var images = ["https://dummyimage.com/300x300/000/fff&text=Image+1", "https://dummyimage.com/300x300/000/fff&text=Image+2", "https://dummyimage.com/300x300/000/fff&text=Image+3"];
$('.btn').click(function(){
$('.btn').removeClass('active').addClass('inactive');
$(this).removeClass('inactive').addClass('active');
if ( $('.btn1').hasClass('active') ) {
$("#output").attr("src",images[0]);
} else if ( $('.btn2').hasClass('active') ) {
$("#output").attr("src",images[1]);
} else if ( $('.btn3').hasClass('active') ) {
$("#output").attr("src",images[2]);
}
});
.active{background:green;}
.inactive{background:grey;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btn btn1 active">
Button 1
</button>
<button class="btn btn2 inactive">
Button 2
</button>
<button class="btn btn3 inactive">
Button 3
</button>
<br>
<br>
<img id="output" src="https://dummyimage.com/300x300/000/fff&text=Image+1">
This is working but I would like the images to transition into each other instead of just suddenly change
I know I can fade out and then in but is there a way to fade one into another instead?