HTML5新增标签--canvas之绘制小方块运动

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>小方块运动</title>
        <style>
            body{
                width: 100%;
                height: 100%;
                background: black;
            }
            #canvas{
                background:#ffffff;
            }
        </style>
    </head>
    <body>
        <canvas id="canvas" width="400" height="400">
            
        </canvas>
        <script>
            var oC=document.getElementById("canvas")
            var oGC=oC.getContext("2d")
            var num=0
            oGC.fillRect(0,0,100,100)
            
            setInterval(function(){
                num++
                oGC.clearRect(0,0,oC.width,oC.height)
                oGC.fillRect(num,num,100,100)
            },10)
        </script>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/AsaZyf/article/details/82700012