1、方块下落:

  1. <style>
  2. canvas{
  3. width: 500px;
  4. height: 300px;
  5. border: 1px solid;
  6. }
  7. </style>
  8. </head>
  9. <body>
  10. <canvas id="can" width="500px" height="300px"></canvas>
  11. <script>
  12. var canvas = document.getElementById('can');
  13. var ctx = canvas.getContext("2d");
  14. // 方块下落:
  15. var height = 100;
  16. var timer = setInterval (function (){
  17. ctx.clearRect(0,0,500,300);
  18. ctx.strokeRect(100,height,50,50);
  19. height += 5;
  20. },1000/30);
  21. </script>
  22. </body>

2、作业:自由落体:掉下去后弹起来