简体   繁体   English

动画不能用于伪元素? IE10

[英]Animations not working on pseudo-elements? IE10

This is a problem for IE10 in particular. 尤其对于IE10,这是一个问题。 I'm animating a pseudo-element. 我正在为伪元素设置动画。 When I hover the pseudo-element, .skew class is added to it, which triggers the CSS animation. 当我悬停伪元素时,将.skew添加.skew类,这将触发CSS动画。 When the animation is finished, animationend removes that .skew class. 动画结束后, animationend会删除该.skew类。

At least that's what happens in Chrome and Firefox, but in IE10 the .skew class is added, but not removed when the animation is finished. 至少在Chrome和Firefox中会发生这种情况,但是在IE10中,添加了.skew类,但在动画完成时并未将其删除。 I'm not exactly sure if that's the case, but it might be because hovering the pseudo-element the first time triggers the animation, but hovering it again doesn't (which would mean the .skew class wasn't removed at the end of the previous animation). 我不确定是否是这种情况,但这可能是因为第一次将.skew悬停在伪元素上会触发动画,但是不会再次悬停(这意味着最后没有删除.skew类)的动画)。

See Here: http://jsfiddle.net/Ldh5g/ 看到这里: http : //jsfiddle.net/Ldh5g/

$("div").bind("animationend webkitAnimationEnd oAnimationEnd", function(){
  $(this).removeClass("skew");  
});

$("div").mouseenter(function(){
    $(this).addClass("skew");
});

Anytime the pseudo-element is hovered, the animation plays. 只要将伪元素悬停,动画就会播放。 This is true for Chrome and Firefox. Chrome和Firefox都是这样。 But in IE10 the animation can't play more than once. 但是在IE10中,动画不能播放多次。 The thing is if I try this on a non-pseudo-element, it works. 问题是,如果我在非伪元素上尝试此操作,它将起作用。 Why? 为什么?

I modify your code with a toggle event. 我使用切换事件修改您的代码。 I haven't tried it but it should work even on IE10 我没有尝试过,但即使在IE10上也应该可以使用

http://jsfiddle.net/Ldh5g/4/ http://jsfiddle.net/Ldh5g/4/

JS JS

$( "div" ).bind( "mouseenter mouseleave", function() {
  $( this ).toggleClass("skew");
});

ie10尚不支持伪元素上的动画事件(冒泡)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM