Javascript 在谷歌appmaker中,可以';无法使requestAnimationFrame工作

Javascript 在谷歌appmaker中,可以';无法使requestAnimationFrame工作,javascript,animation,requestanimationframe,google-app-maker,Javascript,Animation,Requestanimationframe,Google App Maker,不知道是否有人注意到这一点。我可以使用setInterval来制作动画,但是计时并不像我希望的那样精确。但是由于某些原因,我不能让requestAnimationFrame做很多事情 下面代码的目的是让屏幕每250ms闪烁两种不同的颜色,虽然这并不是我最终想要实现的,我使用这个简化的概念只是试图让动画的概念发挥作用。(如果有人想尝试一下,我会尝试让黑色背景每400毫秒闪烁100毫秒) 诚然,我对javascript还相当陌生,但我想知道是否有人注意到类似的情况 我正在尝试的代码,单击按钮调用sa

不知道是否有人注意到这一点。我可以使用setInterval来制作动画,但是计时并不像我希望的那样精确。但是由于某些原因,我不能让requestAnimationFrame做很多事情

下面代码的目的是让屏幕每250ms闪烁两种不同的颜色,虽然这并不是我最终想要实现的,我使用这个简化的概念只是试图让动画的概念发挥作用。(如果有人想尝试一下,我会尝试让黑色背景每400毫秒闪烁100毫秒)

诚然,我对javascript还相当陌生,但我想知道是否有人注意到类似的情况

我正在尝试的代码,单击按钮调用sayHello()


你就快到了

替换

windows.performance.now()

window.performance.now()


希望能有所帮助。

嘿,谢谢你的提醒-我确实抓住了这个问题并纠正了它,但仍然没有成功让requestAnimationFrame在AppMaker中工作。有趣的是,我的代码显然是用javascript编写的。这是谷歌appmaker的一个特例,它阻止了我的代码正确运行。我创建了一个包含脚本的网站,运行良好。不知道怎么了。
function sayHello(){
  var start = window.performance.now();
  var runStart = window.performance.now();
  var my_canvas = app.pages.Run.children.Panel1.children.Canvas.getElement().getElementsByTagName("CANVAS")[0];
  var requestId1;
  var totalDuration = 5000;
  var currentColor = '#000000';

  function animate1(now){
    my_canvas.style.backgroundColor = currentColor;
    console.log('animate now: ' + now + 'win' + windows.performance.now());
    if (now > start+250){
      start = now;
      now = 0;
      if (currentColor === '#ff0000') currentColor = '#000000';
      else currentColor = '#ff0000';
      console.log('switch: ' + window.performance.now());
    }

    if ((window.performance.now - runStart) > totalDuration){
      window.cancelAnimationFrame(requestId1); 
      console.log('done');
    }
    else{
      requestAnimationFrame(animate1);
      console.log('not done');
    }
  }

  function sayGoodbye(){
    window.cancelAnimationFrame(requestId1);
  }

  requestId1 = requestAnimationFrame(animate1);
  console.log('start app' + requestId1);
  console.log('info: ' + start + ' ' + runStart + ' ' + totalDuration);

}