在java脚本中重新设置动画帧

时间:2016-08-24 17:02:31

标签: javascript

我有这个代码,当我在Khan Academy的代码部分测试它时效果非常好,但是当我在代码编辑器上编写它并测试它Chrome或Mozila它没有用!!

HTML代码:

 <img id="cat" src="https://www.kasandbox.org/programming-images/misc/cat-walk.gif"> 

java脚本是:

<script>
 var catEl = document.getElementById("cat");

var startTime = new Date().getTime();
var walkTheCat = function() {
  var currTime = new Date().getTime();
  var secondsElapsed = ((currTime - startTime)/1000)*108;
  var newLeft = secondsElapsed+ "px";
   catEl.style.left = newLeft;
   window.requestAnimationFrame(walkTheCat);
 };
walkTheCat();
</script>

0 个答案:

没有答案