HTML5应用开发与实践【五】【画布绘制动画】

119 阅读1分钟
<!Doctype html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html";charset="utf-8">
        <title>canvas</title>
        <script language=javascript>
		var i;
                var height;
		var width;
		var context;
            function draw()
            {
		
		var canvas=document.getElementById('1');
		if(canvas==null)
		{
			return false;
		}
		context=canvas.getContext('2d');
		//艹这里写成getContent检查了好久
		width=canvas.width;
		height=canvas.height;
		i=0;
		//rotate();
		setInterval("rotate()",80);
            }
		function rotate()
		{
			
			context.clearRect(0,0,width,height);
			context.fillStyle="blue";
			context.fillRect(i,0,20,20);
			i+=20;
		}
        </script>
    </head>
    <body>
        <canvas id="1" style="border: 1px solid skyblue" width="800" height="600">恩?
            <script>
                draw();
            </script>
        </canvas>
    </body>
</html>