下面是一些我不知道如何修改做我想要的js。我需要40秒的延迟后才能激活js,而不是onclick。

// retrieve the element
element = document.getElementById("ani");

// reset the transition by...
element.addEventListener("click", function(e){
e.preventDefault;

// -> removing the class
element.classList.remove("delay-1");

// -> triggering reflow /* The actual magic */
// without this it wouldn't work. Try uncommenting the line and the transition won't be         retriggered.
element.offsetWidth = element.offsetWidth;

// -> and re-adding the class
element.classList.add("delay-1");
}, false);

最佳答案

在指定的毫秒数后,使用setTimeout调用方法/任务。

setTimeout(function() {
    //your code/function here
}, (40*1000)); //40 seconds

10-01 20:46
查看更多