如何将计时事件添加到事件侦听器

时间:2019-08-21 15:30:35

标签: javascript

我需要延迟3秒...

document.addEventListener("DOMContentLoaded", function(event) {
var x = VarPagesInChapter.getValue();
var y = Var_visitedPageCount.getValue();
var progress = Math.round(y/x*100);
document.getElementById('pct').innerHTML = progress+'%';
document.getElementById('radial').classList.add('p'+progress);
});

1 个答案:

答案 0 :(得分:0)

您需要setTimeout()函数:

document.addEventListener("DOMContentLoaded", function(event) {
  console.log( "Loaded at " + performance.now() );
  setTimeout(function() {
    //Your code
    console.log( "I'm ready at " + performance.now() );
  }, 3000); // 3000 milliseconds = 3 sec

});