JS setTimeout() alternative

后端 未结 2 888
余生分开走
余生分开走 2021-02-15 11:27

Like i explain here , i can\'t use window.setTimeout() anymore and any window classical functions like clearInterval etc ...); but i need calling a JS block code as an async one

2条回答
  •  猫巷女王i
    2021-02-15 12:00

    Try using jQuery version 3.0 .animate(), which now uses requestAnimationFrame

      // Creates a jQ object where elem set to index of [0]
      // a plain object with value of 0 `{to:0}`
      // call .animate() chained to the jQ object
      // Animates `{to:0}` value from 0 - 1
      // $({to:0}).animate({to:1}
    
    var duration = 5000;
    $({to:0}).animate({to:1}, duration, function() {
      // do stuff after `duration` elapsed
      $("#messageTimer").html("Happy New Year ! (working version)")
    })
    
    

提交回复
热议问题