If you want to create a custom gif, you'll have to craft it yourself using individual frames. Essentially, you'll generate X number of frames and then utilize keyframes
to cycle through them as the background-image
properties of an absolutely positioned div. At the start, the "gif" is set with the property animation-play-state:paused
, which changes to running
on hover. Of course, you can interchange these properties as needed. Take a look at this:
Your HTML markup:
<div class="gif"></div>
And your CSS styles:
.gif {
position: absolute;
margin: auto;
background-image: url(/path/to/starting.frame);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
animation: play 0.5s infinite steps(1);
animation-play-state: paused;
}
.gif:hover {
animation-play-state: running;
}
@keyframes play {
0% { background-image: url('/path/to/0.frame'); }
15% { background-image: url('/path/to/1.frame'); }
30% { background-image: url('/path/to/2.frame'); }
45% { background-image: url('/path/to/3.frame'); }
60% { background-image: url('/path/to/4.frame'); }
75% { background-image: url('/path/to/5.frame'); }
90% { background-image: url('/path/to/6.frame'); }
100% { background-image: url('/path/to/7.frame'); }
}
You can check out an example that I found and modified here.