Animation How to - Create CSS Sprite Animation








Question

We would like to know how to create CSS Sprite Animation.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div#wrapper {<!--from   w  ww  . j av  a  2s  .co m-->
  width: 64px;
  height: 80px;
  margin: auto;
}

#bike {
  width: 64px;
  height: 80px;
  background-image: url('http://www.java2s.com/style/download.png');
  -webkit-animation: anim 1s steps(6, end) infinite;
}

@-webkit-keyframes anim { 
   0% {background-position: 0px;}
   100%{background-position:-320px;}
}
</style>
</head>
<body>
<body>
  <div id="wrapper">
    <div id="bike"></div>
  </div>
</body>
</body>
</html>

The code above is rendered as follows: