You can add a spinner done in CSS after the element <img>
, that will be removed after the gif is loaded by onload
.
You just have to put the image inside a div
(that one div
will not influence the layout, serves only as a reference).
See example (as the transition is very fast, I left commented the line that hides the spinner so you can see it in the example):
caminhoParaOGif = "https://tctechcrunch2011.files.wordpress.com/2015/08/safe_image.gif";
$("#vidthumb_").on("mouseover", function(){
$(this).after('<span class="loader"></span>');
$('#vidthumb_')
.attr('src', caminhoParaOGif)
.on("load", function(){
// $(this).next().remove(); // descomente esta linha
});
});
*{
position: relative;
}
.loader {
border: 16px solid #f3f3f3; /* cinza */
border-top: 16px solid #3498db; /* azul */
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 2s linear infinite;
position: absolute;
top: 50%;
left: 50%;
margin: -31px 0 0 -31px; /* metade da soma do width + 2x a borda*/
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="display: inline-block;">
<img src="https://www.cleverfiles.com/howto/wp-content/uploads/2016/08/mini.jpg" height="200" width="200" id="vidthumb_" />
</div>
I left as an answer a solution for you.
– Jorge.M