sashomaga

CSS animations

Jul 15th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title></title>
  5.     <link href="style.css" rel="stylesheet" />
  6.     <style>
  7.         @-webkit-keyframes smooth {
  8.             from {
  9.                 left: 100px;
  10.             }
  11.  
  12.             to {
  13.                 left: 1000px;
  14.             }
  15.         }
  16.  
  17.         @-webkit-keyframes translate {
  18.             0% {
  19.                 -webkit-transform: translateX(100px);
  20.             }
  21.  
  22.             100% {
  23.                 -webkit-transform: translateX(1000px);
  24.             }
  25.         }
  26.  
  27.         #div {
  28.             position: absolute;
  29.             left: 100px;
  30.             width: 100px;
  31.             height: 100px;
  32.             border: 1px solid red;
  33.         }
  34.  
  35.         .animate {
  36.             -webkit-animation-name: translate;
  37.             -webkit-animation-duration: 3s;
  38.             -webkit-animation-timing-function: linear;
  39.             /*ease-in -> Slow at the beginning, and then speeds up.
  40. ease-outFast -> Fast at the beginning, and then slows to a stop.
  41. ease-in-out -> Starts slow, speeds up in the middle, and then slows to a stop.
  42. linear -> Moves at an even speed from start to finish.*/
  43.         }
  44.     </style>
  45. </head>
  46. <body>
  47.     <div id="div">div</div>
  48.  
  49.     <button id="anim">anim</button>
  50.     <script>
  51.         var div = document.getElementsByTagName('div')[0];
  52.         document.getElementById('anim').addEventListener('click', function () {
  53.             div.className = "animate";
  54.         }, false);
  55.  
  56.         div.addEventListener('webkitAnimationEnd', function () {
  57.             div.className = "";
  58.             div.style.left = "1000px";
  59.         }, false);
  60.     </script>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment