You should definitely give this code a try.
This code utilizes a callback function for when the button is clicked, causing the slide down effect to occur after the animation completes and then loading the image.
Lazy loading in action!
Hopefully, this will be of assistance to you.
$("#toggleButton").on('click',function(e){
$(".mydiv").slideDown(1000,function(e){
$('.myimg').each(function(e){
$(this).attr('src', $(this).attr('myimage')).css('background','none');
})
});
})
.mydiv {
display: none;
}
img[myimage] {
display:block;
max-width: 100%;
height: auto;
width: 400px;
height: 380px;
background: #000 url(https://rentbluharbor.com/wp-content/uploads/ajax-loading-gif-4.gif) no-repeat center center ;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="toggleButton">Click To Animate</button>
<div class="mydiv">
<img class="myimg" myimage="https://demo.sirv.com/chair.jpg?hue=10" />
</div>
**-- Many thanks! -- **