Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for me to restart a gif with CSS (no JS)?

Tags:

html

css

So I have a piece of CSS like this:

.three-image-widget div.hover-icon img.original { display: block; }
.three-image-widget div.hover-icon img.hovered { display: none; }
.three-image-widget div.hover-icon:hover img.original { display: none; }
.three-image-widget div.hover-icon:hover img.hovered { display: block; }

I have .original images as .pngs and the .hovered images are animated .gifs that I want to start, when hovering over the div.hover-icon elements. I know it's possible to do this with a JavaScript hack like this:

$('div.hover-icon').hover(function(){
    $(this).find('.original').hide(); 
    var hov = $(this).find('.hovered'), 
        copy = hov.attr('src'); 
        hov.attr('src','').attr('src',copy);
});

but can I do the equivalent with pure CSS?

like image 902
Subpar Web Dev Avatar asked Apr 21 '16 18:04

Subpar Web Dev


People also ask

How do you reload a GIF in JavaScript?

To reset a GIF animation with JavaScript, we can add a random query string to the end of the image URL. to add an animate GIF img element. to select the img element with querySelector .

Can you pause a GIF JavaScript?

Freezeframe. js is a library that pauses animated . gifs and enables them to animate on mouse hover / mouse click / touch event, or triggered manually. With this JS library, you'll know how to pause a GIF by writing its data to a canvas element — automatically.

How do you add a GIF in HTML CSS?

You can use <img> tag to insert the GIF on your website. For example: <img src="animation. gif" alt="funny animation GIF">


1 Answers

No you can't. You need to reload the GIF and CSS cannot do this.

like image 71
cnorthfield Avatar answered Oct 01 '22 06:10

cnorthfield