Ball
Code Breakdown
The HTML structure is minimal, consisting of a <div> element with the id "ball" to represent the ball in the animation.
The CSS styles define the appearance and animation of the ball.
The body has its margin and padding set to 0 to remove any default spacing.
The overflow property is set to hidden to prevent scrollbars from appearing.
The #ball selector styles the ball element:
It sets the width and height to 50 pixels, making it a circle with border-radius: 50%.
The background color is set to red.
The position is set to absolute, allowing the ball to be positioned freely.
The initial position is set to top: 0 and left: 0.
The animation property is used to apply the bounce animation for 2 seconds and make it repeat infinitely.
The @keyframes rule defines the bounce animation:
The animation starts at 0% with the ball at the top-left corner.
At 50%, the ball moves to the center of the screen.
At 100%, the ball returns to the top-left corner.
The JavaScript section is empty because no scripting is required for this animation. It uses pure CSS animation.
When you open the HTML file in a web browser, you'll see a red ball bouncing animation. The ball starts at the top-left corner, moves to the center of the screen, and then returns to the top-left corner, creating a continuous bouncing effect. The animation is achieved using CSS keyframes and the animation property applied to the ball element.