1 <head> 2 <meta charset='utf-8' /> 3 <style> 4 #canvas { 5 border: 1px dashed #aaa; 6 } 7 </style> 8 <script src="./ball.js"></script> 9 <script> 10 window.onload = function () { 11 var oCanvas = document.querySelector("#canvas"), 12 oGc = oCanvas.getContext('2d'), 13 width = oCanvas.width, height = oCanvas.height, 14 ball = new Ball( 0, 0 ), 15 speed = 5, 16 vx = speed * Math.cos( 10 * Math.PI / 180 ), 17 vy = speed * Math.sin( 10 * Math.PI / 180 ); 18 19 (function linear() { 20 oGc.clearRect(0, 0, width, height); 21 ball.fill( oGc ); 22 ball.x += vx; 23 ball.y += vy; 24 requestAnimationFrame(linear); 25 })(); 26 } 27 </script> 28 </head> 29 <body> 30 <canvas></canvas> 31 </body>
相关文章![[js高手之路] html5 canvas教程 - 绘制七巧板 - ghostwu](/upload8/allimg/171009/1200332031_lit.png)
![[js高手之路] html5 canvas教程 - 制作一个数码倒计时效果 - ghostwu](/upload8/allimg/171009/110425E08_lit.png)
![[js高手之路] html5 canvas动画教程 - 实时获取鼠标的当前坐标 - ghostwu](/images/defaultpic.gif)
![[js高手之路] html5 canvas系列教程 - 状态详解(save与restore) - ghostwu](/upload8/allimg/170930/15004632T_lit.png)
精彩导读
热门资讯
关注我们