"requestAnimationFrame"메서드가 다음 예제에서 작동하지 않습니다. 콘솔에 오류 메시지가 표시되지 않습니다. 그렇다면이 코드의 오류는 무엇입니까? HTML :"requestAnimationFrame"메서드가 작동하지 않습니다.
<body>
<div id="container">
<canvas id="canvas" width="1024" height="1024"></canvas>
</div>
<script type="text/javascript" src = "Jquery/easy.js"></script>
</body>
자바 스크립트 :
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var chop1 = new Image();
chop1.src = "img/chopper.png";
var chopperX = 0;
var chopperY = 0;
var ascent = 20;
function fly()
{
chopperY += ascent;
ctx.drawImage(chop1, chopperX, chopperY, 30, 80);
requestAnimationFrame(fly);
}
window.onload = function() {
init()
};
function init()
{
chop1.src = "img/chopper.png";
ctx.drawImage(chop1, 0, 0, 30, 80);
fly()
}
;
- "의 drawImage"방법은 "잘 작동하지만 requestAnmationFrame "메소드가 작동하지 않습니다. – sraban
코드에서 수행해야 할 작업은 무엇입니까? ['requestAnimationFrame'] (https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame)은 하나의 매개 변수만을 지원합니다. 그리고 내가 볼 수있는 한 이미지 요소는 문서에 삽입되지 않습니다. 따라서 CSS를 추가하면 아무 효과가 없습니다. –
@ RobW- 나는 ur point를 얻었습니다. 문서에서 위에서 아래로 img를 옮기고 싶습니다. 코드를 조금 편집하지만 여전히 작동하지 않습니다. 코드를 살펴보십시오. 그것의 오류는 무엇입니까? – sraban