简体   繁体   English

自定义Javascript无法在Internet Explorer 9和10中触发

[英]Custom Javascript not firing in internet explorer 9 and 10

First of all this is the script located in the head of my document. 首先,这是我文档开头的脚本。

<script>
    document.addEventListener("DOMContentLoaded", function () {
        var e, t = document.querySelectorAll("div.bounceInDown");
        for (var n = 0, r = t.length; n < r; n++) {
            e = Math.round(Math.random() * 7e3) + "ms";
            t[n].style.animationDelay = e;
            t[n].style.WebkitAnimationDelay = e
        }
    }, false)
</script>

Now I have a class called "bounceInDown" which has a keyframe animation. 现在,我有一个名为“ bounceInDown”的类,该类具有关键帧动画。 All the div elements that have this secondary class applied should bounce down when the website has loaded. 网站加载后,所有应用了该次级类的div元素都应弹开。 Now, the script there makes the bounce with different delay values. 现在,该脚本使跳动具有不同的延迟值。 It just doesnt work in internet explorer. 它只是在Internet Explorer中不起作用。 No idea why. 不知道为什么。 What is wrong with my code? 我的代码有什么问题?

It works in all browsers except IE 它适用于除IE之外的所有浏览器

Well for starters IE9 doesn't support animation , that was only added in IE10 :p 对于初学者来说,IE9不支持animation ,仅在IE10中添加了animation :p

Aside from that, it's possible that it's starting the animation before the DOMContentLoaded event has had a chance to update the delay. 除此之外,有可能在DOMContentLoaded事件有机会更新延迟之前开始动画。 Rather than setting the animation in CSS and adjusting the delay in JS, try setting the entire animation in JS: 与其在CSS中设置动画并在JS中调整延迟,不如在JS中设置整个动画:

t[n].style.animation = "yourAnimationName 1s "+e;

(Replace that 1s with your animation duration) (用动画持续时间替换1s

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

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