One way to make a ball bounce in Javascript is by using the HTML5 canvas element along with basic physics and animation principles. Here's some sample code to create a bouncing ball animation:
1033 chars53 lines
This script will create a canvas element and draw a circle at the center that will move and simulate a bouncing ball. The draw()
function is called repeatedly with a small delay (10ms), which simulates the animation. The drawBall()
function creates a ball at current location with a color fill. Finally, the if
statements will detect if the ball is hitting any of the canvas' boundaries and change the direction accordingly to simulate a bouncing motion.
gistlibby LogSnag