当前位置:   article > 正文

css3D制作立体旋转小方块_css transform: perspective(1000px) rotatey(0deg) r

css transform: perspective(1000px) rotatey(0deg) rotatex(100deg);

 

用到的重要css样式:

1、transform:perspective( );

        perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。

当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本身。

2、transform-style: preserve-3d;

        用于将子元素将保留其 3D 位置。

3、transform: translatez( );

        定义3D 转换,只是用 Z 轴的值,定义距离。

 下面是具体的实例:

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  7. <title>3D</title>
  8. <style type="text/css">
  9. .style{
  10. width: 200px;
  11. height: 200px;
  12. position: absolute;
  13. top: 50%;
  14. left: 50%;
  15. margin-left: -100px;
  16. margin-top: -100px;
  17. transform-style: preserve-3d;/*定义图像的3D*/
  18. animation: xuanzhuan 10s cubic-bezier(0.0,0.0,0.0,0.0) infinite forwards;
  19. }
  20. @-webkit-keyframes xuanzhuan{
  21. 0%{
  22. transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);/*perspctive定义视距*/
  23. }
  24. 10%{
  25. transform:perspective(1000px) rotatex(90deg)rotatey(0deg)rotatez(0deg);
  26. }
  27. 20%{
  28. transform:perspective(1000px) rotatex(90deg)rotatey(0deg)rotatez(90deg);
  29. }
  30. 30%{
  31. transform:perspective(1000px) rotatex(180deg)rotatey(0deg)rotatez(90deg);
  32. }
  33. 40%{
  34. transform:perspective(1000px) rotatex(180deg)rotatey(90deg)rotatez(90deg);
  35. }
  36. 50%{
  37. transform:perspective(1000px) rotatex(270deg)rotatey(90deg)rotatez(90deg);
  38. }
  39. 60%{
  40. transform:perspective(1000px) rotatex(270deg)rotatey(90deg)rotatez(90deg);
  41. }
  42. 80%{
  43. transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);
  44. }
  45. 100%{
  46. transform:perspective(1000px) rotatex(0deg)rotatey(0deg)rotatez(0deg);
  47. }
  48. }
  49. .style>div{
  50. width: 100%;
  51. height: 100%;
  52. position: absolute;
  53. top: 0;
  54. left: 0;
  55. color: white;
  56. font-size: 50px;
  57. text-align: center;
  58. line-height: 200px;
  59. }
  60. .one{
  61. background-color: red;
  62. transform: translatez(100px);/*translatez距离中心轴距离*/
  63. }
  64. .two{
  65. background-color: green;
  66. transform: rotatex(90deg) translatez(100px);
  67. }
  68. .three{
  69. background-color: yellow;
  70. transform: rotatex(180deg) translatez(100px);
  71. }
  72. .four{
  73. background-color: blue;
  74. transform: rotatex(270deg) translatez(100px);
  75. }
  76. .five{
  77. background-color: black;
  78. transform: rotatey(90deg) translatez(100px);
  79. }
  80. .six{
  81. background-color: darkviolet;
  82. transform: rotatey(270deg) translatez(100px);
  83. }
  84. </style>
  85. </head>
  86. <body>
  87. <div class="style">
  88. <div class="one">1</div>
  89. <div class="two">2</div>
  90. <div class="three">3</div>
  91. <div class="four">4</div>
  92. <div class="five">5</div>
  93. <div class="six">6</div>
  94. </div>
  95. </body>
  96. </html>

 效果图如下:

电脑打开观看

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/86736
推荐阅读
相关标签
  

闽ICP备14008679号