Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to get two images, both of which rotate in opposite directions, to rotate simultaneously upon hovering over an area covering both images so that both images pause when not hovering over the area and resume if doing so. I've created a jsfiddle below demonstrating what I'm kind of trying to achieve (although it's for each separate image), but I'm not sure whether or not JavaScript is required to do it and what approach to take.

http://jsfiddle.net/bq8u6g6w/4/
Posted
Comments
Sergey Alexandrovich Kryukov 24-Apr-15 16:23pm    
This is the pure CSS animation, which I really appreciate. But CSS animation is just bound to be limited. So, sorry, I just don't know if you could achieve it with CSS.
I personally would not even try; I would start doing it based on Canvas from the very beginning, something I have good experience with. But I cannot be so sure to strongly advise it, I only say that with Canvas it would not be a problem at all, it would give me really short time to accomplish (provided the static images are already available). So, I don't know, maybe you still explore the CSS opportunity (how about browser compatibility, by the way?)...

If you have related questions, I would gladly try to answer, but for now... let me just award you with my vote of 5 for this pretty interesting question and the good way of asking it. :-)

—SA

1 solution

Yes this is possible:

You need to wrap both images in a container:

HTML
<div id="divWrapper">
<div class="sticker"><img style="border-radius:130px;" src="http://i.imgur.com/pP32yO8.png" /></div> 
<div style="removed:relative;removed26px;removed26px" class="sticker2"><img style="border-radius:104px;" src="http://i.imgur.com/1xHMFDI.png" /></div>
</div>


You then apply your animation classes to the hover state of the container like this:

CSS
#divWrapper:hover .sticker {
  /* Toggle our animation play state to running when we are hovering over our sticker */
  animation-play-state: running;
}


I've updated your fiddle (As per your original, this only works in IE)

http://jsfiddle.net/bq8u6g6w/8/[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900