Animation How to - Create sprite sheet animation








Question

We would like to know how to create sprite sheet animation.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.motion {<!--from   w ww .j a  v  a 2s  .c  o m-->
  width: 200px;
  height: 200px;
  background-image: url("http://www.java2s.com/style/download.png");
  -webkit-animation: play 1.8s steps(15) infinite;
  -moz-animation: play 1.8s steps(15) infinite;
  -ms-animation: play 1.8s steps(15) infinite;
  -o-animation: play 1.8s steps(15) infinite;
  animation: play 1.8s steps(15) infinite;
}

@-webkit-keyframes play {
   from { background-position:0px;}
   to {background-position: -1050px;}
}
@-moz-keyframes play {
   from { background-position:0px;}
   to {background-position: -1050px;}
}
@-ms-keyframes play {
   from { background-position:0px;}
   to {background-position: -1050px;}
}
@-o-keyframes play {
   from { background-position:0px;}
   to {  background-position: -1050px;}
}
@keyframes play {
    from { background-position:0px;}
    to {background-position: -1050px;}
}
</style>
</head>
<body>
  <div class="motion"></div>
</body>
</html>

The code above is rendered as follows: