English 中文(简体)
CSS3 - Animation
  • 时间:2024-12-22

CSS3 - Animation


Previous Page Next Page  

Animation is process of making shape changes and creating motions with elements.

@keyframes

Keyframes will control the intermediate animation steps in CSS3.

Example of key frames with left animation −

@keyframes animation {
   from {background-color: pink;}
   to {background-color: green;}
}
span {
   width: 100px;
   height: 100px;
   background-color: red;
   animation-name: animation;
   animation-duration: 5s;
}

The above example shows height, width, color, name and duration of animation with keyframes syntax.

Moving left animation

<html>
   <head>
      <style type = "text/css">
         h1 {
            -moz-animation-duration: 3s;
            -webkit-animation-duration: 3s;
            -moz-animation-name: spdein;
            -webkit-animation-name: spdein;
         }
         @-moz-keyframes spdein {
            from {
               margin-left:100%;
               width:300%
            }
            to {
               margin-left:0%;
               width:100%;
            }
         }
         @-webkit-keyframes spdein {
            from {
               margin-left:100%;
               width:300%
            }
            to {
               margin-left:0%;
               width:100%;
            }
         }
      </style>
   </head>

   <body>
      <h1>Tutorials Point</h1>
      <p>this is an example of moving left animation .</p>
      <button oncpck = "myFunction()">Reload page</button>
      <script>
         function myFunction() {
            location.reload();
         }
      </script>
   </body>
</html>

It will produce the following result −