HTML & CSS Code Create a Bouncing Ball

Ticker

10/recent/ticker-posts

HTML & CSS Code Create a Bouncing Ball

What n Amazing Bouncing Ball to HTML & CSS Codding

  

HTML CODE

  <!DOCTYPE html>
    <html lang="en">
        <head>
            <title>Page Title</title>
        </head>
        <body>
          <canvas id="cnv"></canvas>
        
         <font size="8"><strong id="para">Bouncing Ball Created From MAA Blogger</b>
         </font>
          <script>
          var a = 80;
          var b = 2;//speed 
          var c = 70;
          var d = 2;//speed
              var w=window.innerWidth;
                var h=window.innerHeight - 100;
                         var cnv=document.getElementById("cnv");
                var ctx=cnv.getContext("2d");
                cnv.width=w;
                cnv.height=h;
                 
                setInterval(function (){
                ctx.clearRect(0,0,w,h);
                ctx.beginPath();
    ctx.arc(c, a, 80, 0, 2 * Math.PI);
    ctx.stroke();
    ctx.fillStyle="#000080";
    ctx.fill();
                if(a>=h-20 || a<20){
                    b = - b;  
                }
                if(c>w-20 || c<20){
                    d = -d;
                }
                a+= b;
                c+= d;
                },10) 
          </script>
        </body>
    </html> 

CSS CODE

#cnv{
    border:solid 10px #000;
    background-color:#bff;
}
#para{
    font-size:large;
}


OUTPUT



Post a Comment

49 Comments

  1. Amazing 😁😁😁😁

    ReplyDelete
  2. Mind-blowing 😄😄😄

    ReplyDelete