老师帮忙检查代码
来源:8-2 编程练习
人生的起源
2019-12-31 00:44:48
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>canvas动画</title> <style> canvas{background-color:lightblue;} </style> </head> <body> <canvas width="800px" height="800px" id="canvas">您的浏览器不支持canvas</canvas> <script> var canvas=document.getElementById("canvas"); var context=canvas.getContext("2d"); //补充代码 var posx = 200, posy = 0, dir = 1; context.fillStyle = 'green'; context.fillRect(200, 0, 100, 100); setInterval(function(){ if(posy >= 800-100){ dir = -1; }else if(posy <= 0){ dir = 1; } posy += 10*dir; context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(posx, posy, 100, 100); }, 100); </script> </body> </html>
1回答
好帮手慕慕子
2019-12-31
同学你好,代码是正确的,继续加油, 祝学习愉快~