html5 canvas 移动小方块

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
body{
    background:pink;
    }
#c1{
    background:white;
    }    


</style>

<script>
window.onload = function ()
{
    var oc = document.getElementById('c1');
    var ogc = oc.getContext('2d');
    var num = 0;
    
    setInterval(function (){
        num++;
        ogc.clearRect(0,0,oc.width,oc.height);
        ogc.fillRect(num,num,100,100);
        },20)
    
    
}
</script>
</head>

<body>
    <canvas id="c1" width="400" height="300">
        <span>请升级您的浏览器</span>
    </canvas>
</body>
</html>

 

posted @ 2015-02-10 21:59  mayufo  阅读(2347)  评论(0编辑  收藏  举报