赞
踩
用到的重要css样式:
1、transform:perspective( );
perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。
当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本身。
2、transform-style: preserve-3d;
用于将子元素将保留其 3D 位置。
3、transform: translatez( );
定义3D 转换,只是用 Z 轴的值,定义距离。
下面是具体的实例:
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <meta http-equiv="X-UA-Compatible" content="ie=edge" />
- <title>3D</title>
- <style type="text/css">
- .style{
- width: 200px;
- height: 200px;
- position: absolute;
- top: 50%;
- left: 50%;
- margin-left: -100px;
- margin-top: -100px;
- transform-style: preserve-3d;/*定义图像的3D*/
- animation: xuanzhuan 10s cubic-bezier(0.0,0.0,0.0,0.0) infinite forwards;
- }
- @-webkit-keyframes xuanzhuan{
- 0%{
- transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);/*perspctive定义视距*/
- }
- 10%{
- transform:perspective(1000px) rotatex(90deg)rotatey(0deg)rotatez(0deg);
- }
- 20%{
- transform:perspective(1000px) rotatex(90deg)rotatey(0deg)rotatez(90deg);
- }
- 30%{
- transform:perspective(1000px) rotatex(180deg)rotatey(0deg)rotatez(90deg);
- }
- 40%{
- transform:perspective(1000px) rotatex(180deg)rotatey(90deg)rotatez(90deg);
- }
- 50%{
- transform:perspective(1000px) rotatex(270deg)rotatey(90deg)rotatez(90deg);
- }
- 60%{
- transform:perspective(1000px) rotatex(270deg)rotatey(90deg)rotatez(90deg);
- }
- 80%{
- transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);
- }
- 100%{
- transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);
- }
- }
- .style>div{
- width: 100%;
- height: 100%;
- position: absolute;
- top: 0;
- left: 0;
- color: white;
- font-size: 50px;
- text-align: center;
- line-height: 200px;
- }
- .one{
- background-color: red;
- transform: translatez(100px);/*translatez距离中心轴距离*/
- }
- .two{
- background-color: green;
- transform: rotatex(90deg) translatez(100px);
- }
- .three{
- background-color: yellow;
- transform: rotatex(180deg) translatez(100px);
- }
- .four{
- background-color: blue;
- transform: rotatex(270deg) translatez(100px);
- }
- .five{
- background-color: black;
- transform: rotatey(90deg) translatez(100px);
- }
- .six{
- background-color: darkviolet;
- transform: rotatey(270deg) translatez(100px);
- }
- </style>
- </head>
- <body>
- <div class="style">
- <div class="one">1</div>
- <div class="two">2</div>
- <div class="three">3</div>
- <div class="four">4</div>
- <div class="five">5</div>
- <div class="six">6</div>
- </div>
- </body>
- </html>
效果图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。