4 <title>CSS Animation Test
</title>
5 <meta name=
"viewport" content=
"initial-scale=0.60, minimum-scale=0.60, maximum-scale=0.60">
6 <style type=
"text/css">
14 Setting the perspective of the contents of the stage
15 but not the stage itself
18 -webkit-perspective: 800;
25 /* Ensure that we're in 3D space */
26 -webkit-transform-style: preserve-3d
;
28 Make the whole set of rows use the x-axis spin animation
29 for a duration of 7 seconds, running infinitely and linearly
31 -webkit-animation-name: x-spin
;
32 -webkit-animation-duration: 7s;
33 -webkit-animation-iteration-count: infinite
;
34 -webkit-animation-timing-function: linear
;
41 -webkit-transform-style: preserve-3d
;
42 -webkit-animation-iteration-count: infinite
;
43 -webkit-animation-timing-function: linear
;
46 .ring > :nth-child(odd) {
47 background-color: #995C7F;
50 .ring > :nth-child(even) {
51 background-color: #835A99;
60 color: rgba
(0,0,0,0.9);
61 -webkit-border-radius: 10px;
65 font-family: 'Georgia', serif
;
73 Set up each row to have a different animation duration
74 and alternating y-axis rotation directions.
77 -webkit-animation-name: y-spin
;
78 -webkit-animation-duration: 5s;
82 -webkit-animation-name: back-y-spin
;
83 -webkit-animation-duration: 4s;
87 -webkit-animation-name: y-spin
;
88 -webkit-animation-duration: 3s;
93 Here we define each of the three individual animations that
94 we will be using to have our 3D rotation effect. The first
95 animation will perform a full rotation on the x-axis, we'll
96 use that on the whole set of objects. The second and third
97 animations will perform a full rotation on the y-axis in
98 opposite directions, alternating directions between rows.
100 Note that you currently have to specify an intermediate step
101 for rotations even when you are using individual transformation
105 @
-webkit-keyframes x-spin
{
106 0% { -webkit-transform: rotateX
(0deg); }
107 50% { -webkit-transform: rotateX
(180deg); }
108 100% { -webkit-transform: rotateX
(360deg); }
111 @
-webkit-keyframes y-spin
{
112 0% { -webkit-transform: rotateY
(0deg); }
113 50% { -webkit-transform: rotateY
(180deg); }
114 100% { -webkit-transform: rotateY
(360deg); }
117 @
-webkit-keyframes back-y-spin
{
118 0% { -webkit-transform: rotateY
(360deg); }
119 50% { -webkit-transform: rotateY
(180deg); }
120 100% { -webkit-transform: rotateY
(0deg); }
124 <script type=
"text/javascript">
126 const POSTERS_PER_ROW
= 12;
127 const RING_RADIUS
= 200;
129 function setup_posters (row
)
131 var posterAngle
= 360 / POSTERS_PER_ROW
;
132 for (var i
= 0; i
< POSTERS_PER_ROW
; i
++) {
133 var poster
= document
.createElement('div');
134 poster
.className
= 'poster';
135 // compute and assign the transform for this poster
136 var transform
= 'rotateY(' + (posterAngle
* i
) + 'deg) translateZ(' + RING_RADIUS
+ 'px)';
137 poster
.style
.webkitTransform
= transform
;
138 // setup the number to show inside the poster
139 var content
= poster
.appendChild(document
.createElement('p'));
140 content
.textContent
= i
;
141 // add the poster to the row
142 row
.appendChild(poster
);
149 setup_posters(document
.getElementById('ring-1'));
150 setup_posters(document
.getElementById('ring-2'));
151 setup_posters(document
.getElementById('ring-3'));
154 // call init once the document is fully loaded
155 window
.addEventListener('load', init
, false);
163 <div id=
"ring-1" class=
"ring"></div>
164 <div id=
"ring-2" class=
"ring"></div>
165 <div id=
"ring-3" class=
"ring"></div>