In our new tutorial I will show you how to create pure CSS3 loading elements (without any images). I think that it can be interesting for you in order to decrease amount of extra images in your project. I prepared three different loading elements. Now, lets check how I made them.
So, lets start
Step 1. HTML
You can see here three elements – our ‘loading’ elements. All of them are very easy – parent element with set of inner DIVs.
01 |
< div class = "main_body" > |
03 |
< div class = "loading1" > |
15 |
< div class = "loading2" > |
27 |
< div class = "loading3" > |
Step 2. CSS
Now, the most interesting step, I will give you styles of each ‘loading’ element. Welcome to check styles of first one:
007 |
background-color : #FFFFFF ; |
012 |
-moz-border-radius: 5px ; |
013 |
-webkit-border-radius: 5px ; |
016 |
-webkit-transform:scale( 0.4 ); |
017 |
-moz-transform:scale( 0.4 ); |
018 |
-o-transform:scale( 0.4 ); |
020 |
-webkit-animation-name:loading 1 ; |
021 |
-webkit-animation-duration: 1.04 s; |
022 |
-webkit-animation-iteration-count:infinite; |
023 |
-webkit-animation- direction :linear; |
024 |
-moz-animation-name:loading 1 ; |
025 |
-moz-animation-duration: 1.04 s; |
026 |
-moz-animation-iteration-count:infinite; |
027 |
-moz-animation- direction :linear; |
028 |
-o-animation-name:loading 1 ; |
029 |
-o-animation-duration: 1.04 s; |
030 |
-o-animation-iteration-count:infinite; |
031 |
-o-animation- direction :linear; |
033 |
.loading 1 > div:nth-child( 1 ) { |
037 |
-webkit-transform:rotate( -90 deg); |
038 |
-moz-transform:rotate( -90 deg); |
039 |
-o-transform:rotate( -90 deg); |
041 |
-webkit-animation-delay: 0.39 s; |
042 |
-moz-animation-delay: 0.39 s; |
043 |
-o-animation-delay: 0.39 s; |
045 |
.loading 1 > div:nth-child( 2 ) { |
049 |
-webkit-transform:rotate( -45 deg); |
050 |
-moz-transform:rotate( -45 deg); |
051 |
-o-transform:rotate( -45 deg); |
053 |
-webkit-animation-delay: 0.52 s; |
054 |
-moz-animation-delay: 0.52 s; |
055 |
-o-animation-delay: 0.52 s; |
057 |
.loading 1 > div:nth-child( 3 ) { |
061 |
-webkit-transform:rotate( 0 deg); |
062 |
-moz-transform:rotate( 0 deg); |
063 |
-o-transform:rotate( 0 deg); |
065 |
-webkit-animation-delay: 0.65 s; |
066 |
-moz-animation-delay: 0.65 s; |
067 |
-o-animation-delay: 0.65 s; |
069 |
.loading 1 > div:nth-child( 4 ) { |
073 |
-webkit-transform:rotate( 45 deg); |
074 |
-moz-transform:rotate( 45 deg); |
075 |
-o-transform:rotate( 45 deg); |
077 |
-webkit-animation-delay: 0.78 s; |
078 |
-moz-animation-delay: 0.78 s; |
079 |
-o-animation-delay: 0.78 s; |
081 |
.loading 1 > div:nth-child( 5 ) { |
085 |
-webkit-transform:rotate( 90 deg); |
086 |
-moz-transform:rotate( 90 deg); |
087 |
-o-transform:rotate( 90 deg); |
089 |
-webkit-animation-delay: 0.91 s; |
090 |
-moz-animation-delay: 0.91 s; |
091 |
-o-animation-delay: 0.91 s; |
093 |
.loading 1 > div:nth-child( 6 ) { |
097 |
-webkit-transform:rotate( 135 deg); |
098 |
-moz-transform:rotate( 135 deg); |
099 |
-o-transform:rotate( 135 deg); |
101 |
-webkit-animation-delay: 1.04 s; |
102 |
-moz-animation-delay: 1.04 s; |
103 |
-o-animation-delay: 1.04 s; |
105 |
.loading 1 > div:nth-child( 7 ) { |
109 |
-webkit-transform:rotate( 180 deg); |
110 |
-moz-transform:rotate( 180 deg); |
111 |
-o-transform:rotate( 180 deg); |
113 |
-webkit-animation-delay: 1.17 s; |
114 |
-moz-animation-delay: 1.17 s; |
115 |
-o-animation-delay: 1.17 s; |
117 |
.loading 1 > div:nth-child( 8 ) { |
121 |
-webkit-transform:rotate( -135 deg); |
122 |
-moz-transform:rotate( -135 deg); |
123 |
-o-transform:rotate( -135 deg); |
125 |
-webkit-animation-delay: 1.3 s; |
126 |
-moz-animation-delay: 1.3 s; |
127 |
-o-animation-delay: 1.3 s; |
130 |
@-webkit-keyframes loading 1 { |
131 |
0% { background-color : #000000 } |
132 |
100% { background-color : #FFFFFF } |
134 |
@-moz-keyframes loading 1 { |
135 |
0% { background-color : #000000 } |
136 |
100% { background-color : #FFFFFF } |
138 |
@-o-keyframes loading 1 { |
139 |
0% { background-color : #000000 } |
140 |
100% { background-color : #FFFFFF } |
As you can see – I used CSS3 animation with keyframes, each step (point) is separated with delay with each other. Now, please review styles of our second ‘loading’ element:
006 |
-webkit-transform:scale( 0.6 ); |
007 |
-moz-transform:scale( 0.6 ); |
008 |
-o-transform:scale( 0.6 ); |
011 |
background-color : #FFFFFF ; |
016 |
-moz-border-radius: 15px ; |
017 |
-webkit-border-radius: 15px ; |
020 |
-webkit-animation-name:loading 2 ; |
021 |
-webkit-animation-duration: 1.04 s; |
022 |
-webkit-animation-iteration-count:infinite; |
023 |
-webkit-animation- direction :linear; |
024 |
-moz-animation-name:loading 2 ; |
025 |
-moz-animation-duration: 1.04 s; |
026 |
-moz-animation-iteration-count:infinite; |
027 |
-moz-animation- direction :linear; |
028 |
-o-animation-name:loading 2 ; |
029 |
-o-animation-duration: 1.04 s; |
030 |
-o-animation-iteration-count:infinite; |
031 |
-o-animation- direction :linear; |
033 |
.loading 2 > div:nth-child( 1 ) { |
037 |
-webkit-animation-delay: 0.39 s; |
038 |
-moz-animation-delay: 0.39 s; |
039 |
-o-animation-delay: 0.39 s; |
041 |
.loading 2 > div:nth-child( 2 ) { |
045 |
-webkit-animation-delay: 0.52 s; |
046 |
-moz-animation-delay: 0.52 s; |
047 |
-o-animation-delay: 0.52 s; |
049 |
.loading 2 > div:nth-child( 3 ) { |
053 |
-webkit-animation-delay: 0.65 s; |
054 |
-moz-animation-delay: 0.65 s; |
055 |
-o-animation-delay: 0.65 s; |
057 |
.loading 2 > div:nth-child( 4 ) { |
061 |
-webkit-animation-delay: 0.78 s; |
062 |
-moz-animation-delay: 0.78 s; |
063 |
-o-animation-delay: 0.78 s; |
065 |
.loading 2 > div:nth-child( 5 ) { |
069 |
-webkit-animation-delay: 0.91 s; |
070 |
-moz-animation-delay: 0.91 s; |
071 |
-o-animation-delay: 0.91 s; |
073 |
.loading 2 > div:nth-child( 6 ) { |
077 |
-webkit-animation-delay: 1.04 s; |
078 |
-moz-animation-delay: 1.04 s; |
079 |
-o-animation-delay: 1.04 s; |
081 |
.loading 2 > div:nth-child( 7 ) { |
085 |
-webkit-animation-delay: 1.17 s; |
086 |
-moz-animation-delay: 1.17 s; |
087 |
-o-animation-delay: 1.17 s; |
089 |
.loading 2 > div:nth-child( 8 ) { |
093 |
-webkit-animation-delay: 1.3 s; |
094 |
-moz-animation-delay: 1.3 s; |
095 |
-o-animation-delay: 1.3 s; |
098 |
@-webkit-keyframes loading 2 { |
099 |
0% { background-color : #000000 } |
100 |
100% { background-color : #FFFFFF } |
102 |
@-moz-keyframes loading 2 { |
103 |
0% { background-color : #000000 } |
104 |
100% { background-color : #FFFFFF } |
106 |
@-o-keyframes loading 2 { |
107 |
0% { background-color : #000000 } |
108 |
100% { background-color : #FFFFFF } |
I used here the same idea as for the first element, but, with slightly changed styles. And finally – our third ‘loading’ element:
02 |
background-color : #FFFFFF ; |
03 |
border : 1px solid #000000 ; |
10 |
-webkit-transform:scale( 0.8 ); |
11 |
-moz-transform:scale( 0.8 ); |
12 |
-o-transform:scale( 0.8 ); |
14 |
-webkit-animation-name:loading 3 ; |
15 |
-webkit-animation-duration: 1.2 s; |
16 |
-webkit-animation-iteration-count:infinite; |
17 |
-webkit-animation- direction :linear; |
18 |
-moz-animation-name:loading 3 ; |
19 |
-moz-animation-duration: 1.2 s; |
20 |
-moz-animation-iteration-count:infinite; |
21 |
-moz-animation- direction :linear; |
22 |
-o-animation-name:loading 3 ; |
23 |
-o-animation-duration: 1.2 s; |
24 |
-o-animation-iteration-count:infinite; |
25 |
-o-animation- direction :linear; |
27 |
.loading 3 > div:nth-child( 1 ) { |
29 |
-webkit-animation-delay: 0.24 s; |
30 |
-moz-animation-delay: 0.24 s; |
31 |
-o-animation-delay: 0.24 s; |
33 |
.loading 3 > div:nth-child( 2 ) { |
35 |
-webkit-animation-delay: 0.48 s; |
36 |
-moz-animation-delay: 0.48 s; |
37 |
-o-animation-delay: 0.48 s; |
39 |
.loading 3 > div:nth-child( 3 ) { |
41 |
-webkit-animation-delay: 0.72 s; |
42 |
-moz-animation-delay: 0.72 s; |
43 |
-o-animation-delay: 0.72 s; |
45 |
.loading 3 > div:nth-child( 4 ) { |
47 |
-webkit-animation-delay: 0.96 s; |
48 |
-moz-animation-delay: 0.96 s; |
49 |
-o-animation-delay: 0.96 s; |
51 |
.loading 3 > div:nth-child( 5 ) { |
53 |
-webkit-animation-delay: 1.2 s; |
54 |
-moz-animation-delay: 1.2 s; |
55 |
-o-animation-delay: 1.2 s; |
58 |
@-webkit-keyframes loading 3 { |
60 |
-webkit-transform:scale( 1.2 ); |
64 |
-webkit-transform:scale( 0.7 ); |
68 |
@-moz-keyframes loading 3 { |
70 |
-moz-transform:scale( 1.2 ); |
74 |
-moz-transform:scale( 0.7 ); |
78 |
@-o-keyframes loading 3 { |
80 |
-o-transform:scale( 1.2 ); |
84 |
-o-transform:scale( 0.7 ); |
Conclusion
That is all for today. We have just created three different ‘loading’ elements. I hope that everything have been easy for you and you like result. Good luck!