HTML5 CSS3 Tempting Example: 3D cube rotation animation

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/lmj623565791/article/details/34120047

Creative from: http://www.html5tricks.com/demo/html5-3d-cube/index.html, students give me a sample, feel very good, just can't think out the actual use. But the effect is very dazzling ~


Knowledge Points:

1, perspective, Transform's review

2, CSS3 Backgroud realize the background. The little 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>

The previous 3D product show has already said how to make a cube, and that there are numbers on it. 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); }

The same: stage as the arena. Cube sets the effect of the child element to 3d, and then each polygon rotates and sets the Translatez and then forms a cube.

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, left-to-right 3-pixel strips, from top to bottom 3-pixel strips. Then set the background size to 2.5em 2.5em. The background is then displayed repeatedly. Effects such as the following (I added a border):



Today's full Effect:


Can see the cube has been formed, and finally added to the animation, do not think the animation is very complex, in fact very easy~

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. Start at Translatez ( -10em) Rotatex (0) Rotatey (0deg); At the end: Translatez ( -10em) Rotatex (360deg) Rotatey (360deg); That is, the same time around the X, Y axis 360 degrees rotation.

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 careful parameter setting, I will also write a blog that describes the properties of CSS3 separately after w3cschool~.



Well, the final effect is over.

For the original site look, there is a slight difference:

Since it adds a radial gradient to each of the polygons, 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 finally the same ~


Source code click to download








HTML5 CSS3 Tempting Example: 3D cube rotation animation

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.