Animationend事件不触发:after元素
Animationend event not firing on :after element
我在:after元素上设置了一个动画,在animationend事件上设置了一个事件处理程序。但是,在IE10/IE11中,animationend事件永远不会触发。
$(document).ready(function(){
var testdiv = $('#testid');
testdiv.on('animationend webkitAnimationEnd', function(){
document.writeln('Animation has ended');
});
});
JSFiddle: http://jsfiddle.net/Robin_f/R3qEG/
真心希望有人能帮我解决这个问题。
在搜索网页后,很明显IE还不支持绑定到伪元素上的动画事件。我在我的原始帖子中发布的jsFiddle使这一点更加明显,它不会在动画结束时触发事件。
看起来像是IE的bug,或者可能是DEV团队设计的,不知道。一个变通的方法,真的很糟糕,可以在元素上设置一个假动画来处理IE10/11:
#testid {
animation: fakeAnim ease-in-out 1s 4 alternate;
}
@keyframes fakeAnim {
to {
opacity: 1;
}
}
注意: firefox将触发事件两次,应该过滤它,使firefox只触发一次逻辑。
可以使用:
var isIE = !! navigator.userAgent.match(/Trident'/7'./);
$(document).ready(function () {
var testdiv = $('#testid');
testdiv.on('animationend webkitAnimationEnd', function (e) {
if (!isIE && e.originalEvent.animationName === "fakeAnim") return;
alert('Animation has ended');
});
});
参见DEMO jsFiddle
这是因为:
文档。在JSFiddle环境中不允许写操作,并且可能会中断你的小提琴。
您可以使用console.log()
来调试:
$(document).ready(function(){
var testdiv = $('#testid');
testdiv.on('animationend webkitAnimationEnd', function(){
console.log('Animation has ended');
});
});
更新小提琴
或:
$(document).ready(function(){
var testdiv = $('#testid');
testdiv.on('animationend webkitAnimationEnd', function(){
$('#testid').append('Animation has ended');
});
});
更新小提琴
相关文章:
- Make:如果父元素溢出,after元素将扩展到全宽
- jQuery:如何选择所有具有:before或:after的伪元素
- 如果元素存在,如何使用 .after() 作为 .html()
- 为什么 jQuery .after() 不链接新元素
- 将 css 样式应用于 javascript 调用中的 :after 伪元素
- 使用 after() 时获取元素属性
- 使用 Jquery .after() 来移动元素
- 对 :after 元素的背景图像进行动画处理
- 方法“after”不适用于尚未在 DOM 中的元素
- 选择 :after 元素在 Jquery 选择器中不起作用
- 获取页脚以显示带有 z 索引的 AFTER 元素
- 使用 javascript 修改伪元素 :after's width
- 有没有任何方法可以重置元素的CSS规则:after/:before
- CSS伪元素上的事件侦听器,例如::after和::before
- Jquery/JS-如何切换元素的:after,:before
- 追加元素AFTER加载
- 如何将jQuery fadeIn与使用.after创建的元素一起使用
- 强制不要对伪元素 (:after) 使用换行符
- 访问after()后附加的元素
- Animationend事件不触发:after元素