I have the following images:
Static image | Running animation | Completion animation
And I use the following code ( jsfiddle example ):
$(function() { $("#link-gif").hover( function() { $(this).css("background-image", "url('http://i.imgur.com/HhsBws5.gif')"); }, function() { $(this).css("background-image", "url('http://i.imgur.com/WLFzz3S.gif')"); } ); });
#link-gif { width:150px; height:40px; border:1px solid #39464E; background-image:url('http://i.imgur.com/YgLJoVH.png'); background-size:contain; background-repeat:no-repeat; background-position:bottom center; cursor:pointer; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="link"> <div id="link-gif"> </div> </div>
So, in general, I want this to happen: I first upload a static image. When someone hovered over #link-gif , the starting gif animation starts, and when you hover it to the left, the ending animation starts.
For some reason, when you hover over an image, the image is not animated. It just comes to the end of the gif. Does anyone know why this is happening?
javascript jquery html css animation
bryan
source share