css3 webkit animation stop on div:hover

*爱你&永不变心* 提交于 2019-11-29 14:11:13

问题


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


回答1:


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/




回答2:


If you use a more complex label you can achieve this without Javascript. I used .parent:hover .child { -webkit-animation-play-state: paused; } and it worked perfectly.



来源:https://stackoverflow.com/questions/6556039/css3-webkit-animation-stop-on-divhover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!