简体   繁体   English

为什么 js window.cancelAnimationFrame() 不起作用?

[英]Why the js window.cancelAnimationFrame() not working?

Code代码

Not Working:-不工作: -

let animateFrame ;
function animate (){
    if(animateFrame > 200 ) {
        window.cancelAnimationFrame(animateFrame );
    } 
    console.log(animateFrame ) ;
    animateFrame =  window.requestAnimationFrame(animate);
}
animate()

Working Don't Know Why:-工作不知道为什么:-

let animateFrame ;
function animate (){

   animateFrame =  window.requestAnimationFrame(animate);
   if(animateFrame > 200 ) {
        window.cancelAnimationFrame(animateFrame );
   }
   console.log(animateFrame ) ;
}
animate()

It would be great if you explain it through example please.如果您通过示例进行解释,那就太好了。

Thank you for u r time.感谢您的 r 时间。

In the first example:在第一个示例中:

  1. If the frame is over 200, you cancel the animation如果帧数超过 200,则取消 animation
  2. You log the frame你记录框架
  3. You start the animation (which makes the cancel pointless)您启动 animation (这使得取消毫无意义)

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

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