javascript - How to make a gif animate on hover, go back to normal after unhovered -
so have bunch of elements like:
<div class="hover-icon one"> <img class="original" src="sswe-images/circle_customer notifications.png"/> <img class="hovered one" src="sswe-images/customer-notifications.gif" /> </div> <div class="hover-icon two"> <img class="original" src="sswe-images/circle_field service tools.png" /> <img class="hovered" src="sswe-images/field-service-tools.gif" /> </div> <div class="hover-icon three"> <img class="original" src="sswe-images/circle_remote connectivity.png" /> <img class="hovered" src="sswe-images/remote-connectivity.gif" /> </div>
where .original
placeholders , .hovered
gifs want animate on hover, go normal state after mouse leaves. attempt is:
$('div.hover-icon').hover(function(){ var orig = $(this).find('.original'); orig.hide(); var hov = $(this).find('.hovered'); hov.attr('src', hov.attr('src') + "?x=" + math.random()); settimeout(function(){ hov.show(); }, 100); /* $(this).mouseleave(function(){ hov.hide(); orig.show(); });*/ });
but reason commented out section because it's not working. it's causing kinds of craziness. proper pattern should using here?
the basic html structure correct. use css though , codepen http://codepen.io/ryanpcmcquen/pen/ggqdi
.hover-icon { position: relative; margin: 0 auto; } .hover-icon img { position: absolute; } .hover-icon img.original:hover { opacity: 0; }
Comments
Post a Comment