当前位置:   article > 正文

html5和css3实现3d正方体旋转_html正方体3d旋转

html正方体3d旋转

1.创建一个div盒子:

  1. <div class="container">
  2. <div class="cube">
  3. <div class="side front">前面</div>
  4. <div class="side back">后面</div>
  5. <div class="side top">顶部</div>
  6. <div class="side bottom">底部</div>
  7. <div class="side left">左侧</div>
  8. <div class="side right">右侧</div>
  9. </div>
  10. </div>

2.设置样式style,实现旋转功能:

1.设置六个面的宽,高,颜色等:

  1. .side {
  2. position: absolute;
  3. width: 200px;
  4. height: 200px;
  5. background-color: rgba(190, 54, 23, 0.8);
  6. border: 1px solid #3a13d5;
  7. }

  2. 创建3D视角 : 

  1. .container {
  2. margin-top: 200px;
  3. margin-left: 200px;
  4. perspective: 1000px;

3.使用动画让正方体旋转 :

  1. .cube {
  2. width: 200px;
  3. height: 200px;
  4. position: relative;
  5. transform-style: preserve-3d;
  6. animation: spin 5s infinite linear;
  7. }

4.设置六个面的坐标:

  1. .front {
  2. transform: translateZ(100px);
  3. }
  4. .back {
  5. transform: rotateY(180deg) translateZ(100px);
  6. }
  7. .top {
  8. transform: rotateX(90deg) translateZ(100px);
  9. }
  10. .bottom {
  11. transform: rotateX(-90deg) translateZ(100px);
  12. }
  13. .left {
  14. transform: rotateY(-90deg) translateZ(100px);
  15. }
  16. .right {
  17. transform: rotateY(90deg) translateZ(100px);
  18. }

5.用动画keyframes让其旋转起来:

  1. @keyframes spin {
  2. 0% {
  3. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
  4. }
  5. 100% {
  6. transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
  7. }
  8. }

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

闽ICP备14008679号