Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css3 webkit animation stop on div:hover

I try to make an animation with webkit-animation and @-webkit-keyframes. I have a div animated with child div inside.

And i would stop the webkit-animation of the parent when my mouse is over a child.

Any Examples ?

Thanks

like image 643
Geraud Mathe Avatar asked Jul 02 '11 08:07

Geraud Mathe


People also ask

How do I stop an animation from hover?

By setting the animation-play-state to paused on hover, the animation will pause, your click targets will stop moving, and your users will be happy.

What is @- WebKit keyframes in CSS?

A @-webkit-keyframes block contains rule sets called keyframes. A keyframe defines the style that will be applied for that moment within the animation. The animation engine will smoothly interpolate style between the keyframes.

Is hover a CSS animation?

What is a CSS hover animation? A CSS hover animation occurs when a user hovers over an element, and the element responds with motion or another transition effect. It's used to highlight key items on a web page and it's an effective way to enhance your site's interactivity. Take a look at the example below.


1 Answers

Unfortunately there is no parent selector in CSS, see here. You will have to use a bit of javascript to select the parent and tell it to pause.

The pause declaration in CSS goes like this:

-webkit-animation-play-state: paused | running;

The javascript (jQuery, in this case) would look something like this:

$(".child").hover(
  function(){
    $(this).parent().css("-webkit-animation-play-state", "paused");
},
  function(){
    $(this).parent().css("-webkit-animation-play-state", "running");
});

See a live demo here:

http://jsfiddle.net/UFepV/

like image 143
methodofaction Avatar answered Oct 21 '22 20:10

methodofaction