Code for Animation

Code for Animation

Here's a basic example where a box glides with varying colors across the screen.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Animation Example</title>
    <style>
        @keyframes slideAndColorChange {
            0% {
                transform: translateX(0px);
                background-color: blue;
            }
            50% {
                transform: translateX(200px);
                background-color: red;
            }
            100% {
                transform: translateX(0px);
                background-color: yellow;
            }
        }
        .animated-box {
            width: 100px;
            height: 100px;
            background-color: blue;
            position: relative;
            animation-name: slideAndColorChange;
            animation-duration: 4s;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
        }
    </style>
</head>
<body>
    <div class="animated-box"></div>
</body>
</html>

Explanation of code

Keyframes slideAndColorChange

  • The box's initial position with a blue backdrop is where it starts at 0%.
  • At 50%, the box's background color turns red and it travels 200 pixels to the right.
  • When the box reaches 100%, its backdrop becomes yellow and it returns to its initial location.

CSS for .animated-box:

  • The box's size is determined by its height and breadth.
  • Since the transform property in keyframes depends on the position: relative; to move the box, it is employed.
  • The animation is linked to the specified keyframes by the animation-name: slideAndColorChange.
  • animation-duration: 4s; this specifies that the animation will take 4 seconds to complete one loop.
  • ease-in-out animation timing feature causes the animation to begin and conclude gently before accelerating in the middle.
  • The animation repeats endlessly when the animation-iteration-count is set to infinite.

logo

CSS

Code for Animation

Beginner 5 Hours

Code for Animation

Here's a basic example where a box glides with varying colors across the screen.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Animation Example</title>
    <style>
        @keyframes slideAndColorChange {
            0% {
                transform: translateX(0px);
                background-color: blue;
            }
            50% {
                transform: translateX(200px);
                background-color: red;
            }
            100% {
                transform: translateX(0px);
                background-color: yellow;
            }
        }
        .animated-box {
            width: 100px;
            height: 100px;
            background-color: blue;
            position: relative;
            animation-name: slideAndColorChange;
            animation-duration: 4s;
            animation-timing-function: ease-in-out;
            animation-iteration-count: infinite;
        }
    </style>
</head>
<body>
    <div class="animated-box"></div>
</body>
</html>

Explanation of code

Keyframes slideAndColorChange

  • The box's initial position with a blue backdrop is where it starts at 0%.
  • At 50%, the box's background color turns red and it travels 200 pixels to the right.
  • When the box reaches 100%, its backdrop becomes yellow and it returns to its initial location.

CSS for .animated-box:

  • The box's size is determined by its height and breadth.
  • Since the transform property in keyframes depends on the position: relative; to move the box, it is employed.
  • The animation is linked to the specified keyframes by the animation-name: slideAndColorChange.
  • animation-duration: 4s; this specifies that the animation will take 4 seconds to complete one loop.
  • ease-in-out animation timing feature causes the animation to begin and conclude gently before accelerating in the middle.
  • The animation repeats endlessly when the animation-iteration-count is set to infinite.

Similar Data Science Tutorials

Related tutotials

Frequently Asked Questions for css

line

Copyrights © 2024 letsupdateskills All rights reserved