Animation How to - Create animated gears








Question

We would like to know how to create animated gears.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
body {<!--from w  w w.j a  v a  2 s  .  c  o m-->
  background: #EEE;
}
i {
  display: block;
  position: absolute;
  width: 30px;
  height: 30px;
  top: 30px;
  left: 30px;
  background: url(http://i.imgur.com/lOBxb.png);
  -webkit-animation: barrelRoll 2s infinite linear;
  -webkit-animation-play-state: paused;
}

i:last-of-type {
  top: 22px;
  left: 56px;
  -webkit-animation-name: invertBarrelRoll;
}

div:hover>i {
  -webkit-animation-play-state: running;
}

@-webkit-keyframes barrelRoll { 
0% {-webkit-transform: rotate(0deg);}
100%{-webkit-transform:rotate(360deg);}
}
@-webkit-keyframes invertBarrelRoll { 
0% {-webkit-transform: rotate(0deg);}
100%{-webkit-transform:rotate(-360deg);}
}
</style>
</head>
<body>
  <div>
    <i></i><i></i>
  </div>
</body>
</html>

The code above is rendered as follows: