2012-05-27 6 views
0

내 애니메이션의 캔버스와 webkitrequestAnimation 프레임을 사용하고 있습니다. 그러나 애니메이션이 순식간에 부드럽지 않습니다. 너무 빨라서 어떤 애니메이션도 볼 수 없습니다. 어떻게 애니메이션을 부드럽게 만드나요? 예상대로 라인 (24)에 구문 오류에서 떨어져 나를 위해 작동html5 애니메이션을 어떻게 부드럽게 만드나요?

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Wave 2</title> 

</head> 
<body> 
<canvas id="canvas" width="400" height="400"></canvas> 

<script> 
window.onload = function() { 
var canvas = document.getElementById('canvas'), 
context = canvas.getContext('2d'), 
angle = 0, 
range = 50, 
centerY = canvas.height/2, 
xspeed = 1, 
yspeed = 0.05, 
xpos = 0, 
ypos = centerY; 
context.lineWidth = 2; 
(function drawFrame() { 
window.webkitrequestAnimationFrame(drawFrame, canvas); 

context.beginPath(); 
context.moveTo(xpos, ypos); 
//Calculate the new position. 
xpos += xspeed; 
angle += yspeed; 
ypos = centerY + Math.sin(angle) * range; 
context.lineTo(xpos, ypos); 
context.stroke(); 
}()); 
}; 
</script> 
</body> 
</html> 

답변

1

:

window.webkitrequestAnimationFrame(drawFrame, canvas); 

window.webkitRequestAnimationFrame(drawFrame, canvas); 

체크 아웃이 페이지의 대답은 : How to use requestAnimationFrame

이 요청을 서면으로 여러분을 안내 할 것입니다 웹킷을 기반으로하는 모든 호환 웹 브라우저에서 작동하는 애니메이션 기능. Safari 또는 Chrome 이외의 브라우저를 사용하는 경우 오류가있는 동작을 설명 할 수 있습니다.

여기서는 createjs.com이 HTML5 캔버스 및 애니메이션 작업을위한 훌륭한 API를 제공하기 때문에 여기에서 옹호하고자합니다. 데모 및 소스를 확인하십시오!

관련 문제