Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108220
  • 博文数量: 40
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 423
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-15 11:55
文章分类

全部博文(40)

文章存档

2016年(36)

2015年(2)

2013年(2)

我的朋友

分类: jQuery

2016-03-26 09:32:21

让canvas画的正方形动起来

点击(此处)折叠或打开

  1. <!DOCTYPE html >
  2. <html>
  3.  <head>
  4.     <title>cars</title>
  5.     <script src=""></script>
  6.  </head>
  7.  <body>
  8.    <canvas id ="canvas" width="200" height="200"></canvas>
  9.    <script>
  10.      var canvas = document.getElementById("canvas");
  11.      var ctx = canvas.getContext("2d");
  12.      var position = 0;
  13.      setInterval(function(){
  14.      ctx.clearRect(0,0,200,200);
  15.      ctx.fillRect(position,0,20,20);
  16.      position++;
  17.      if(position > 200){
  18.      position = 0;
  19.      }
  20.      },30)
  21.    </script>
  22.  </body>
  23. </html>

阅读(1025) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~