A
A
Andrey Skuratov2017-11-09 17:27:02
JavaScript
Andrey Skuratov, 2017-11-09 17:27:02

Is it possible to control gif on :hover?

Tell me, is there any plugin on jQuery that, when hovering over a picture.gif, the animation of the gif itself would work, and when the cursor was removed from the picture, it would play in the opposite direction (regardless of whether the gif played to the end or not) ??

I saw something similar on one site, but it was done through svg, it’s very difficult and the structure of all this is not clear.
And another question is why, with a hover, if the GIF plays to the end, then with a second hover, it immediately takes on the final form? Can this one be fixed somehow so that with every hover it starts all over again ???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Zhivagin, 2019-08-16
@BenderIsGreat34

Read about the principles of KISS, Dry. And about strict / non-strict comparison in JS.
Specifically for this code - that's enough, I think.
In general, for refactoring it would be nice to understand the complexity of basic algorithms - link , another link
Well, it's good to know the language. For example, do not litter the global scope with vars in 2019 :) To be honest, it seems that you can remember about the indexOf method and reduce this function at times

A
Andrey Kvartsov, 2017-11-15
@kolesov_prod

For example:

<div class="gif">
 <img src="animation.gif">
</div>

.gif {
 width: 100px;
 height: 100px;
 background: url(static.jpg);
}

.gif img {
 display: none;
}

.gif:hover img {
 display: block;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question