麻烦老师检查

来源:8-2 编程练习

Yuri沫

2020-04-24 15:20:46

<!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=150, posy=0, dir=1;

        

        context.fillStyle="green";

        

        setInterval(function(){

            posy += 10*dir;

            context.clearRect(0,0,canvas.width,canvas.height);

            context.fillRect(posx,posy,50,50);


            if(posy + 50 >= canvas.height){

             dir = -1;

            }else if(posy <= 0){

             dir = 1;

            }

        },100);

    </script>

</body>

</html>


写回答

1回答

好帮手慕码

2020-04-24

同学你好,代码是正确的,继续加油, 祝学习愉快~

0

0 学习 · 4826 问题

查看课程

相似问题