Tuesday 6 August 2013

EXAMPLES OF PSEUDO-ELEMENTS ANIMATIONS AND TRANSITIONS - Part 3

EXAMPLE 3

AnimatingTransitioningPseudoElements03
How could we dare to leave out the indispensable spinner loading animation!
The idea here is to merge colors through the rotation. It’s very simple!

The Markup

1
<div class="loading"></div>
We’ll just use one single element for the markup.

The CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
.loading  {
    background: rgba(0, 50, 250, 0);
    position: relative;
    margin: 5em auto 0 auto;
    width: 3em;
    height: 3em;
    animation-name:rotate;
}
 
.loading,
.loading:before,
.loading:after  {
    border-radius: 100%;
    animation-duration: 3s;
    animation-iteration-count: infinite;
    animation-timing-function: ease-in;
}
 
.loading:before,
.loading:after  {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: inherit;
    height: inherit;
}
 
.loading:before  {
    background: rgba(200, 250, 100, 0);
    animation-name: ring;
}
 
.loading:after  {
    background: rgba(250, 0, 200, 0);
    animation-name: ring2;
}
 
@keyframes rotate  {
    0%  {
        transform: rotateZ(0deg) scaleX(0.1) scaleY(0.1) translateZ(0);
        box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5),
                    inset 0 0.8em 0 rgba(252, 150, 0, 0.5),
                    inset -0.8em 0 0 rgba(0, 255, 0, 0.5),
                    inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
    }
     
    /* hidden */
     
    85%, 100%  {
     
    /* 360deg * 10 */
     
        transform: rotateZ(3600deg) scaleX(2.01) scaleY(2) translateZ(0);
        box-shadow: inset 0 0 0 rgba(255, 0, 0, 0),
                    inset 0 0 0 rgba(252, 150, 0, 0),
                    inset 0 0 0 rgba(0, 255, 0, 0),
                    inset 0 0 0 rgba(0, 150, 255, 0);
    }
}
 
@keyframes ring  {
    0%  {
        transform: scaleX(0.1) scaleY(0.5);
        box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5),
                    inset 0 0.8em 0 rgba(252, 150, 0, 0.5),
                    inset -0.8em 0 0 rgba(0, 255, 0, 0.5),
                    inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
    }
     
    /* hidden */
     
    75%, 100%  {
        transform: scaleX(2) scaleY(2.1);
        box-shadow: inset 0 0 0 rgba(255, 0, 0, 0),
                    inset 0 0 0 rgba(252, 150, 0, 0),
                    inset 0 0 0 rgba(0, 255, 0, 0),
                    inset 0 0 0 rgba(0, 150, 255, 0);
    }
}
 
@keyframes ring2  {
    0%  {
        transform: scaleX(0.5) scaleY(0.1);
        box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5),
                    inset 0 0.8em 0 rgba(252, 150, 0, 0.5),
                    inset -0.8em 0 0 rgba(0, 255, 0, 0.5),
                    inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
    }
     
    /* hidden */
     
    65%, 100%  {
        transform: scaleX(2) scaleY(2.1);
        box-shadow: inset 0 0 0 rgba(255, 0, 0, 0),
                    inset 0 0 0 rgba(252, 150, 0, 0),
                    inset 0 0 0 rgba(0, 255, 0, 0),
                    inset 0 0 0 rgba(0, 150, 255, 0);
    }
}
This is a great example of experimenting with timings and speeds to get a really smooth animation.