HTML5 CSS3 Tempting Example: 3D cube Rotation Animation demo

Source: Internet
Author: User

Creative from: http://www.html5tricks.com/demo/html5-3d-cube/index.html, students give me an example, feel very good, but I really can't think of the actual use, but the effect is very dazzling ~


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><div class= "Stage" >    <div class= "Cube" >        <div class= "Font" ></div>        <div class= ' back ' ></div>        <div class= ' left ' ></div>        <div class= ' right ' ></ div>        <div class= "Top" ></div>        <div class= "Bottom" ></div>    </div></ Div></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 (SI, 226, 248, 0.5) 3p            X, 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 ~








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.