This article introduces the tempting example of HTML5+CSS3:3D cube Rotation Animation example, as follows
:
Knowledge Points:
1, perspective, Transform's review
2, CSS3 backgroud realization of the background, that is, the small princess on the surface
3, @-webkit-keyframes realization Animation
Html:
<body> <p class= "Stage" > <p class= "Cube" > <p class= "Font" ></p> < P class= ' back ' ></p> <p class= ' left ' ></p> <p class= ' right ' ></p> <p class= "Top" ></p> <p class= "Bottom" ></p> </p> </p> </body >
In front of the 3D product show has said how to make a cube, and that there are numbers, theoretically more complicated than this, although the wood has this dazzle ~ here is not much to say.
Css:
HTML {background:-webkit-radial-gradient (center, ellipse, #430d6d 0, #000000 100%); Background:radial-gradient (ellipse at center, #430d6d 0, #000000 100%); height:100%; }. stage {-webkit-perspective:1000px; Width:20em; Height:20em; left:50%; top:50%; Margin-left: -10em; Margin-top: -10em; Position:absolute; }. cube {position:absolute; width:100%; height:100%; -webkit-transform-style:preserve-3d; -webkit-transform:rotatex ( -20deg) Rotatey ( -20deg); }. Cube * {background:-webkit-linear-gradient (left, Rgba (226, 248, 0.5) 0px, RGBA (54, 226, 248, 0.5) 3px, RGBA (0, 0, 0, 0) 0px),-webkit-linear-gradient (Top, Rgba (SI, 226, 248, 0.5) 0px, RGBA (54, 226, 248, 0. 5) 3px, Rgba (0, 0, 0, 0) 0px); -webkit-background-size:2.5em 2.5em; Background-color:rgba (0, 0, 0, 0.5); Position:absolute; width:100%; height:100%; BORDER:2PX Solid Rgba (54, 226, 248, 0.5); -webkit-box-shadow:0 0 5em rgba (0, 128, 0, 0.4); }. Font {-webkit-transform:translatez (10em); }. Back {-webkit-transform:rotatex (180deg) Translatez (10em); }. Left {-webkit-transform:rotatey ( -90deg) Translatez (10em); }. Right {-webkit-transform:rotatey (90deg) Translatez (10em); }. Top {-webkit-transform:rotatex (90deg) Translatez (10em); }. Bottom {-webkit-transform:rotatex ( -90deg) Translatez (10em); }
Similarly: stage as the staging, cube sets the effect of the child element to 3d, then each face is rotated and set Translatez and then the cube is formed.
Set the Backgroud code for each polygon:
Background:-webkit-linear-gradient (left , rgba (226, 248, 0.5) 0px, rgba (SI, 226, 248, 0.5) 3px, RGBA (0, 0, 0, 0) 0px), -webkit-linear-gradient ( top, rgba (226, 248, 0.5) 0px, Rgba (54, 226, 248, 0.5) 3PX, rgba (0, 0, 0, 0) 0px); -webkit-background-size:2.5em 2.5em;
Background settings, 3 pixels from left to right, 3 pixels from top to bottom, then set the background size to 2.5em 2.5em and then repeat the background as follows (I added a border):
Now the full effect:
Can see the cube has been formed, and finally add the animation on the line, do not think the animation is very complex, in fact, very simple ~
Define an animation frame:
@-webkit-keyframes spin { from { -webkit-transform:translatez ( -10em) Rotatex (0) Rotatey (0deg); Transform:translatez ( -10em) Rotatex (0) Rotatey (0deg); } To { -webkit-transform:translatez ( -10em) Rotatex (360deg) Rotatey (360deg); Transform:translatez ( -10em) Rotatex (360deg) Rotatey (360deg); } }
The name is spin, starting at Translatez ( -10em) Rotatex (0) Rotatey (0deg); At the end: Translatez ( -10em) Rotatex (360deg) Rotatey (360deg); That is, rotate 360 degrees around the x, Y axis at the same time.
Finally, add this animation property to our cube:
. Cube { -webkit-animation:6s spin linear infinite; Position:absolute; width:100%; height:100%; -webkit-transform-style:preserve-3d; -webkit-transform:rotatex ( -20deg) Rotatey ( -20deg); }
Set time for animation time 6s, animation spin, speed of uniform linear, infinite cycle infinite;
For more detailed parameter settings, you can refer to w3cschool~ later I will also write a separate description of the properties of CSS3 Blog ~
Well, the final effect is done ~
For the original site look, there is a slight difference:
Because it adds a radial gradient to each polygon, we add:
. Cube *:before { display:block; Background:-webkit-radial-gradient (center, Ellipse, RGBA (0, 0, 0, 0) 30%, rgba (0, +, 0, 0.2) 100%); Background:radial-gradient (ellipse at center, RGBA (0, 0, 0, 0) 30%, rgba (0,, 0, 0.2) 100%); Content: "; height:100%; width:100%; Position:absolute; }
Take advantage of this pseudo-element of before and then set the radial gradient ~ ~ Now it's the same ~
SOURCE Click to download: Demo
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.