bouncing ball

[Total: 0    Average: 0/5]

A small, enjoying script simulating a bouncing ball on the ground.

Body Code:

<DIV id=ball style="WIDTH: 15px; POSITION: absolute; HEIGHT: 15px">
<img border="0" src="/js/pic1.gif" width="15" height="15" 


<script language=JavaScript>
  var xPos=30; var yPos=10;
  var xVel=14; var yVel=0;
  var xAcc=0; var yAcc=10;
  var T=0.1;
  var isNetscape = navigator.appName=="Netscape";

  setInterval("animate()", 20);
  function BallClicked(){yVel=-30}
  function animate() {

    xVel+=xAcc*T; yVel+=yAcc*T;
    xPos+=xVel*T; yPos+=yVel*T;

    if (xPos<15) xVel=Math.abs(xVel);
    if (xPos>315) xVel=-Math.abs(xVel);
    //if (yPos<20) yVel=Math.abs(yVel);
    if ((yVel>0)&&((yPos>90))){ yVel=-0.95*yVel; yPos=180-yPos;}

    if (isNetscape) { 

        document.ball.left = xPos; = yPos;

    } else {;;


Times Viewed: 8

Leave a Reply

Your email address will not be published. Required fields are marked *