老师请检查
来源:8-2 编程练习
mokongh
2019-06-09 10:29:51
<!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 poseX = 200,poseY = 0 ,dir = 1;
//补充代码
var timer = setInterval(function(){
poseY +=10 *dir;
context.fillStyle = "#00f";
context.clearRect(0,0,context.canvas.width,context.canvas.height);
context.fillRect(poseX,poseY,50,50);
if(poseY+50 >= 800){
dir = -1;
}else if(poseY <= 0){
dir = 1;
}
},100);
</script>
</body>
</html>
1回答
樱桃小胖子
2019-06-09
效果实现的是可以的,继续加油哦!