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:loading1; |
021 | -webkit-animation-duration:1.04s; |
022 | -webkit-animation-iteration-count:infinite; |
023 | -webkit-animation-direction:linear; |
024 | -moz-animation-name:loading1; |
025 | -moz-animation-duration:1.04s; |
026 | -moz-animation-iteration-count:infinite; |
027 | -moz-animation-direction:linear; |
028 | -o-animation-name:loading1; |
029 | -o-animation-duration:1.04s; |
030 | -o-animation-iteration-count:infinite; |
031 | -o-animation-direction:linear; |
033 | .loading1 > div:nth-child(1) { |
037 | -webkit-transform:rotate(-90deg); |
038 | -moz-transform:rotate(-90deg); |
039 | -o-transform:rotate(-90deg); |
041 | -webkit-animation-delay:0.39s; |
042 | -moz-animation-delay:0.39s; |
043 | -o-animation-delay:0.39s; |
045 | .loading1 > div:nth-child(2) { |
049 | -webkit-transform:rotate(-45deg); |
050 | -moz-transform:rotate(-45deg); |
051 | -o-transform:rotate(-45deg); |
053 | -webkit-animation-delay:0.52s; |
054 | -moz-animation-delay:0.52s; |
055 | -o-animation-delay:0.52s; |
057 | .loading1 > div:nth-child(3) { |
061 | -webkit-transform:rotate(0deg); |
062 | -moz-transform:rotate(0deg); |
063 | -o-transform:rotate(0deg); |
065 | -webkit-animation-delay:0.65s; |
066 | -moz-animation-delay:0.65s; |
067 | -o-animation-delay:0.65s; |
069 | .loading1 > div:nth-child(4) { |
073 | -webkit-transform:rotate(45deg); |
074 | -moz-transform:rotate(45deg); |
075 | -o-transform:rotate(45deg); |
077 | -webkit-animation-delay:0.78s; |
078 | -moz-animation-delay:0.78s; |
079 | -o-animation-delay:0.78s; |
081 | .loading1 > div:nth-child(5) { |
085 | -webkit-transform:rotate(90deg); |
086 | -moz-transform:rotate(90deg); |
087 | -o-transform:rotate(90deg); |
089 | -webkit-animation-delay:0.91s; |
090 | -moz-animation-delay:0.91s; |
091 | -o-animation-delay:0.91s; |
093 | .loading1 > div:nth-child(6) { |
097 | -webkit-transform:rotate(135deg); |
098 | -moz-transform:rotate(135deg); |
099 | -o-transform:rotate(135deg); |
101 | -webkit-animation-delay:1.04s; |
102 | -moz-animation-delay:1.04s; |
103 | -o-animation-delay:1.04s; |
105 | .loading1 > div:nth-child(7) { |
109 | -webkit-transform:rotate(180deg); |
110 | -moz-transform:rotate(180deg); |
111 | -o-transform:rotate(180deg); |
113 | -webkit-animation-delay:1.17s; |
114 | -moz-animation-delay:1.17s; |
115 | -o-animation-delay:1.17s; |
117 | .loading1 > div:nth-child(8) { |
121 | -webkit-transform:rotate(-135deg); |
122 | -moz-transform:rotate(-135deg); |
123 | -o-transform:rotate(-135deg); |
125 | -webkit-animation-delay:1.3s; |
126 | -moz-animation-delay:1.3s; |
127 | -o-animation-delay:1.3s; |
130 | @-webkit-keyframes loading1 { |
131 | 0%{ background-color:#000000 } |
132 | 100%{ background-color:#FFFFFF } |
134 | @-moz-keyframes loading1 { |
135 | 0%{ background-color:#000000 } |
136 | 100%{ background-color:#FFFFFF } |
138 | @-o-keyframes loading1 { |
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:loading2; |
021 | -webkit-animation-duration:1.04s; |
022 | -webkit-animation-iteration-count:infinite; |
023 | -webkit-animation-direction:linear; |
024 | -moz-animation-name:loading2; |
025 | -moz-animation-duration:1.04s; |
026 | -moz-animation-iteration-count:infinite; |
027 | -moz-animation-direction:linear; |
028 | -o-animation-name:loading2; |
029 | -o-animation-duration:1.04s; |
030 | -o-animation-iteration-count:infinite; |
031 | -o-animation-direction:linear; |
033 | .loading2 > div:nth-child(1) { |
037 | -webkit-animation-delay:0.39s; |
038 | -moz-animation-delay:0.39s; |
039 | -o-animation-delay:0.39s; |
041 | .loading2 > div:nth-child(2) { |
045 | -webkit-animation-delay:0.52s; |
046 | -moz-animation-delay:0.52s; |
047 | -o-animation-delay:0.52s; |
049 | .loading2 > div:nth-child(3) { |
053 | -webkit-animation-delay:0.65s; |
054 | -moz-animation-delay:0.65s; |
055 | -o-animation-delay:0.65s; |
057 | .loading2 > div:nth-child(4) { |
061 | -webkit-animation-delay:0.78s; |
062 | -moz-animation-delay:0.78s; |
063 | -o-animation-delay:0.78s; |
065 | .loading2 > div:nth-child(5) { |
069 | -webkit-animation-delay:0.91s; |
070 | -moz-animation-delay:0.91s; |
071 | -o-animation-delay:0.91s; |
073 | .loading2 > div:nth-child(6) { |
077 | -webkit-animation-delay:1.04s; |
078 | -moz-animation-delay:1.04s; |
079 | -o-animation-delay:1.04s; |
081 | .loading2 > div:nth-child(7) { |
085 | -webkit-animation-delay:1.17s; |
086 | -moz-animation-delay:1.17s; |
087 | -o-animation-delay:1.17s; |
089 | .loading2 > div:nth-child(8) { |
093 | -webkit-animation-delay:1.3s; |
094 | -moz-animation-delay:1.3s; |
095 | -o-animation-delay:1.3s; |
098 | @-webkit-keyframes loading2 { |
099 | 0%{ background-color:#000000 } |
100 | 100%{ background-color:#FFFFFF } |
102 | @-moz-keyframes loading2 { |
103 | 0%{ background-color:#000000 } |
104 | 100%{ background-color:#FFFFFF } |
106 | @-o-keyframes loading2 { |
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:loading3; |
15 | -webkit-animation-duration:1.2s; |
16 | -webkit-animation-iteration-count:infinite; |
17 | -webkit-animation-direction:linear; |
18 | -moz-animation-name:loading3; |
19 | -moz-animation-duration:1.2s; |
20 | -moz-animation-iteration-count:infinite; |
21 | -moz-animation-direction:linear; |
22 | -o-animation-name:loading3; |
23 | -o-animation-duration:1.2s; |
24 | -o-animation-iteration-count:infinite; |
25 | -o-animation-direction:linear; |
27 | .loading3 > div:nth-child(1) { |
29 | -webkit-animation-delay:0.24s; |
30 | -moz-animation-delay:0.24s; |
31 | -o-animation-delay:0.24s; |
33 | .loading3 > div:nth-child(2) { |
35 | -webkit-animation-delay:0.48s; |
36 | -moz-animation-delay:0.48s; |
37 | -o-animation-delay:0.48s; |
39 | .loading3 > div:nth-child(3) { |
41 | -webkit-animation-delay:0.72s; |
42 | -moz-animation-delay:0.72s; |
43 | -o-animation-delay:0.72s; |
45 | .loading3 > div:nth-child(4) { |
47 | -webkit-animation-delay:0.96s; |
48 | -moz-animation-delay:0.96s; |
49 | -o-animation-delay:0.96s; |
51 | .loading3 > div:nth-child(5) { |
53 | -webkit-animation-delay:1.2s; |
54 | -moz-animation-delay:1.2s; |
55 | -o-animation-delay:1.2s; |
58 | @-webkit-keyframes loading3 { |
60 | -webkit-transform:scale(1.2); |
64 | -webkit-transform:scale(0.7); |
68 | @-moz-keyframes loading3 { |
70 | -moz-transform:scale(1.2); |
74 | -moz-transform:scale(0.7); |
78 | @-o-keyframes loading3 { |
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!