We received a lot of feedback on this article CSS3 Loading elements, so we decided to prepare the second part of this article. Where we will create 4 new loading elements. All of them use pure CSS3 animation and don’t use images. Let’s review them.
So, lets start
Step 1. HTML
You can see here four elements – our new ‘loading’ elements. Every of them have a very easy structure.
01 | <div class="main_body"> |
03 | <div class="loading1"> |
07 | <div class="loading2"> |
12 | <div class="loading3"> |
19 | <div class="loading4"> |
Step 2. CSS
Now, the most interesting step, I will give you CSS styles of every ‘loading’ element. Welcome to check styles of the first one:
02 | background-color: #000; |
05 | border: 30px solid #FFF; |
06 | border-right-width: 0; |
08 | box-shadow: 0 0 10px 5px #009933; |
10 | -webkit-animation: anim1 1s linear infinite; |
11 | -moz-animation: anim1 1s linear infinite; |
12 | -ms-animation: anim1 1s linear infinite; |
13 | -o-animation: anim1 1s linear infinite; |
14 | animation: anim1 1s linear infinite; |
17 | @-webkit-keyframes anim1 { |
18 | from { -webkit-transform: rotateX(45deg) rotateZ(0deg); } |
19 | 50% { -webkit-transform: rotateX(0deg) rotateZ(180deg); } |
20 | to { -webkit-transform: rotateX(45deg) rotateZ(360deg); } |
22 | @-moz-keyframes anim1 { |
23 | from { -moz-transform: rotateX(45deg) rotateZ(0deg); } |
24 | 50% { -moz-transform: rotateX(0deg) rotateZ(180deg); } |
25 | to { -moz-transform: rotateX(45deg) rotateZ(360deg); } |
27 | @-ms-keyframes anim1 { |
28 | from { -ms-transform: rotateX(45deg) rotateZ(0deg); } |
29 | 50% { -ms-transform: rotateX(0deg) rotateZ(180deg); } |
30 | to { -ms-transform: rotateX(45deg) rotateZ(360deg); } |
33 | from { -o-transform: rotateX(45deg) rotateZ(0deg); } |
34 | 50% { -o-transform: rotateX(0deg) rotateZ(180deg); } |
35 | to { -o-transform: rotateX(45deg) rotateZ(360deg); } |
38 | from { transform: rotateX(45deg) rotateZ(0deg); } |
39 | 50% { transform: rotateX(0deg) rotateZ(180deg); } |
40 | to { transform: rotateX(45deg) rotateZ(360deg); } |
As you can see – we used CSS3 animation (with keyframes). This element looks like 3D button, all because of border-right-width: 0. This property emulates a push 3d button. Now, please review styles of our second ‘loading’ element:
02 | background-color: #009933; |
11 | background-color: #FFFFFF; |
15 | -webkit-animation-name:anim2; |
16 | -webkit-animation-duration:2.0s; |
17 | -webkit-animation-iteration-count:infinite; |
18 | -webkit-animation-direction:linear; |
19 | -webkit-animation-timing-function:ease; |
20 | -moz-animation-name:anim2; |
21 | -moz-animation-duration:2.0s; |
22 | -moz-animation-iteration-count:infinite; |
23 | -moz-animation-direction:linear; |
24 | -moz-animation-timing-function:ease; |
25 | -ms-animation-name:anim2; |
26 | -ms-animation-duration:2.0s; |
27 | -ms-animation-iteration-count:infinite; |
28 | -ms-animation-direction:linear; |
29 | -ms-animation-timing-function:ease; |
30 | -o-animation-name:anim2; |
31 | -o-animation-duration:2.0s; |
32 | -o-animation-iteration-count:infinite; |
33 | -o-animation-direction:linear; |
34 | -o-animation-timing-function:ease; |
36 | animation-duration:2.0s; |
37 | animation-iteration-count:infinite; |
38 | animation-direction:linear; |
39 | animation-timing-function:ease; |
42 | @-webkit-keyframes anim2 { |
47 | @-moz-keyframes anim2 { |
52 | @-ms-keyframes anim2 { |
This element uses css3 animation with keyframes too, and it looks like loading slider. The next one element:
10 | .loading3 > div:nth-child(2), .loading3 > div:nth-child(3) { |
11 | background-color: rgba(255, 255, 255, 0.2); |
12 | border: 5px solid #FFF; |
14 | box-shadow: 0 0 5px 0 #009933; |
20 | border-bottom-width: 0; |
22 | -webkit-animation: anim3 2s linear infinite; |
23 | -moz-animation: anim3 2s linear infinite; |
24 | -ms-animation: anim3 2s linear infinite; |
25 | -o-animation: anim3 2s linear infinite; |
26 | animation: anim3 2s linear infinite; |
28 | .loading3 > div:nth-child(2) { |
33 | .loading3 > div:nth-child(3) { |
34 | border-color: #009933; |
38 | -webkit-animation-delay:0.5s; |
39 | -moz-animation-delay:0.5s; |
40 | -ms-animation-delay:0.5s; |
41 | -o-animation-delay:0.5s; |
45 | @-webkit-keyframes anim3 { |
46 | from { -webkit-transform: rotateY(0deg); } |
47 | 50% { -webkit-transform: rotateY(180deg); } |
48 | to { -webkit-transform: rotateY(360deg); } |
50 | @-moz-keyframes anim3 { |
51 | from { -moz-transform: rotateY(0deg); } |
52 | 50% { -moz-transform: rotateY(180deg); } |
53 | to { -moz-transform: rotateY(360deg); } |
55 | @-ms-keyframes anim3 { |
56 | from { -ms-transform: rotateY(0deg); } |
57 | 50% { -ms-transform: rotateY(180deg); } |
58 | to { -ms-transform: rotateY(360deg); } |
61 | from { -o-transform: rotateY(0deg); } |
62 | 50% { -o-transform: rotateY(180deg); } |
63 | to { -o-transform: rotateY(360deg); } |
66 | from { transform: rotateY(0deg); } |
67 | 50% { transform: rotateY(180deg); } |
68 | to { transform: rotateY(360deg); } |
This is more interesting element, it looks like two semi-transparent circles in space around the label ‘loading’. We should generate 2 different circles and rotate them in Y coordinate, also we should set delay for the second circle. The last one element:
02 | background: none repeat scroll 0 0 #EEEEEE; |
03 | border-color: #009933; |
06 | border-width: 2px 2px 50px; |
11 | -webkit-animation: anim4 1s linear infinite; |
12 | -moz-animation: anim4 2s linear infinite; |
13 | -ms-animation: anim4 1s linear infinite; |
14 | -o-animation: anim4 1s linear infinite; |
15 | animation: anim4 1s linear infinite; |
18 | background: none repeat scroll 0 0 #EEEEEE; |
19 | border: 18px solid #009933; |
29 | background: none repeat scroll 0 0 #009933; |
30 | border: 18px solid #EEEEEE; |
40 | @-webkit-keyframes anim4 { |
41 | from { -webkit-transform: rotateZ(0deg); } |
42 | 50% { -webkit-transform: rotateZ(180deg); } |
43 | to { -webkit-transform: rotateZ(360deg); } |
45 | @-moz-keyframes anim4 { |
46 | from { -moz-transform: rotateZ(0deg); } |
47 | 50% { -moz-transform: rotateZ(180deg); } |
48 | to { -moz-transform: rotateZ(360deg); } |
50 | @-ms-keyframes anim4 { |
51 | from { -ms-transform: rotateZ(0deg); } |
52 | 50% { -ms-transform: rotateZ(180deg); } |
53 | to { -ms-transform: rotateZ(360deg); } |
56 | from { -o-transform: rotateZ(0deg); } |
57 | 50% { -o-transform: rotateZ(180deg); } |
58 | to { -o-transform: rotateZ(360deg); } |
61 | from { transform: rotateZ(0deg); } |
62 | 50% { transform: rotateZ(180deg); } |
63 | to { transform: rotateZ(360deg); } |
[sociallocker]
[/sociallocker]
Conclusion
That is all for today. We have just created four different ‘loading’ elements. I hope that everything have been easy for you and you like our result. Good luck!