In today’s lesson, we have made the animated gears with CSS3. The result looks very nice. I have used CSS3 keyframes, animation and transforms (rotate) in order to achieve this result. Please pay attention – current demo works well in Firefox and Chrome / Safari (webkit).
Here are samples and downloadable package:
Ok, download the example files and lets start coding !
Step 1. HTML
As usual, we start with the HTML. Here is the html code of our result. There are easy DIV elements.
index.html
1 | <div class="container"> |
2 | <div class="gear" id="gear1"></div> |
3 | <div class="gear" id="gear2"></div> |
4 | <div class="gear" id="gear3"></div> |
5 | <div class="gear" id="gear4"></div> |
6 | <div class="gear" id="gear5"></div> |
7 | <div class="gear" id="gear6"></div> |
8 | <div class="gear" id="gear7"></div> |
Step 2. CSS
Here are the CSS styles of our animated gears.
css/layout.css
002 | @-webkit-keyframes ckw { |
004 | -moz-transform: rotate(0deg); |
005 | -webkit-transform: rotate(0deg); |
008 | -moz-transform: rotate(360deg); |
009 | -webkit-transform: rotate(360deg); |
012 | @-moz-keyframes ckw { |
014 | -moz-transform: rotate(0deg); |
015 | -webkit-transform: rotate(0deg); |
018 | -moz-transform: rotate(360deg); |
019 | -webkit-transform: rotate(360deg); |
022 | @-webkit-keyframes cckw { |
024 | -moz-transform: rotate(360deg); |
025 | -webkit-transform: rotate(360deg); |
028 | -moz-transform: rotate(0deg); |
029 | -webkit-transform: rotate(0deg); |
032 | @-moz-keyframes cckw { |
034 | -moz-transform: rotate(360deg); |
035 | -webkit-transform: rotate(360deg); |
038 | -moz-transform: rotate(0deg); |
039 | -webkit-transform: rotate(0deg); |
047 | -moz-animation-timing-function: linear; |
048 | -moz-animation-iteration-count: infinite; |
049 | -moz-animation-direction: normal; |
050 | -moz-animation-delay: 0; |
051 | -moz-animation-play-state: running; |
052 | -moz-animation-fill-mode: forwards; |
053 | -webkit-animation-timing-function: linear; |
054 | -webkit-animation-iteration-count: infinite; |
055 | -webkit-animation-direction: normal; |
056 | -webkit-animation-delay: 0; |
057 | -webkit-animation-play-state: running; |
058 | -webkit-animation-fill-mode: forwards; |
061 | background: url('../images/g1.png') no-repeat 0 0; |
066 | -moz-animation-name: ckw; |
067 | -moz-animation-duration: 10s; |
068 | -webkit-animation-name: ckw; |
069 | -webkit-animation-duration: 10s; |
072 | background: url('../images/g2.png') no-repeat 0 0; |
077 | -moz-animation-name: cckw; |
078 | -moz-animation-duration: 16.84s; |
079 | -webkit-animation-name: cckw; |
080 | -webkit-animation-duration: 16.84s; |
083 | background: url('../images/g3.png') no-repeat 0 0; |
088 | -moz-animation-name: ckw; |
089 | -moz-animation-duration: 13.5s; |
090 | -webkit-animation-name: ckw; |
091 | -webkit-animation-duration: 13.5s; |
094 | background: url('../images/g4.png') no-repeat 0 0; |
099 | -moz-animation-name: cckw; |
100 | -moz-animation-duration: 20.2s; |
101 | -webkit-animation-name: cckw; |
102 | -webkit-animation-duration: 20.2s; |
105 | background: url('../images/g1.png') no-repeat 0 0; |
110 | -moz-animation-name: ckw; |
111 | -moz-animation-duration: 10s; |
112 | -webkit-animation-name: ckw; |
113 | -webkit-animation-duration: 10s; |
116 | background: url('../images/g2.png') no-repeat 0 0; |
121 | -moz-animation-name: cckw; |
122 | -moz-animation-duration: 16.84s; |
123 | -webkit-animation-name: cckw; |
124 | -webkit-animation-duration: 16.84s; |
127 | background: url('../images/g3.png') no-repeat 0 0; |
132 | -moz-animation-name: ckw; |
133 | -moz-animation-duration: 13.5s; |
134 | -webkit-animation-name: ckw; |
135 | -webkit-animation-duration: 13.5s; |
Step 3. Images
I have used next images:




Conclusion
Hope you enjoyed with new tutorial, don’t forget to tell thanks and leave a comment 🙂 Good luck!