• transform—3D立方体


    1、思路分析

    第一步:首先需要一个大盒子,承载立方体的六个面;

    第二步:立方体的六个面需要3D转化在特定的位置,拼接成一个立方体;

    第三步:设置动画;

    2、代码实现

    第一步:创建div并且设置样式:

        <style>
          .box {
            width: 150px;
            height: 150px;
            background-color: pink;
            margin: 200px auto;
            position: relative;
          }
          .box > div {
            width: 100%;
            height: 100%;
            position: absolute;
            text-align: center;
            line-height: 150px;
            font-size: 20px;
          }
          </style>
        <div class="box">
            <div class="front">front</div>
            <div class="back">back</div>
            <div class="left">left</div>
            <div class="right">right</div>
            <div class="top">top</div>
            <div class="bottom">bottom</div>
        </div>

    第二步:创建六个面,并且在父元素.box 设置立体效果

    transform-style: preserve-3d;

    transform: rotateX(45deg) rotateY(45deg);
          .box .front {
            background-color: lawngreen;
            transform: translateZ(75px);
          }
          .box .back {
            background-color: lightcoral;
            transform: translateZ(-75px);
          }
          .box .left {
            background-color: darkmagenta;
            transform: rotateY(-90deg) translateZ(75px);
          }
          .box .right {
            background-color: paleturquoise;
            transform: rotateY(90deg) translateZ(75px);
          }
          .box .top {
            background-color: salmon;
            transform: rotateX(90deg) translateZ(75px);
          }
          .box .bottom {
            background-color: blue;
            transform: rotateX(-90deg) translateZ(75px);
          }

    显示效果:

    第三步设置动画:

           在.box中设置:animate
          animation: move 5s ease infinite alternate;
       
    
          @keyframes move {
            from {
              transform: rotateX(45deg) rotateY(45deg);
            }
            to {
              transform: rotateX(270deg) rotateY(270deg);
            }
          }

    3、完整代码

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
          .box {
            width: 150px;
            height: 150px;
            background-color: pink;
            margin: 200px auto;
            position: relative;
            transform-style: preserve-3d;
            transform: rotateX(45deg) rotateY(45deg);
            animation: move 5s ease infinite alternate;
          }
          @keyframes move {
            from {
              transform: rotateX(45deg) rotateY(45deg);
            }
            to {
              transform: rotateX(270deg) rotateY(270deg);
            }
          }
    
          .box > div {
            width: 100%;
            height: 100%;
            position: absolute;
            text-align: center;
            line-height: 150px;
            font-size: 20px;
          }
          .box .front {
            background-color: lawngreen;
            transform: translateZ(75px);
          }
          .box .back {
            background-color: lightcoral;
            transform: translateZ(-75px);
          }
          .box .left {
            background-color: darkmagenta;
            transform: rotateY(-90deg) translateZ(75px);
          }
          .box .right {
            background-color: paleturquoise;
            transform: rotateY(90deg) translateZ(75px);
          }
          .box .top {
            background-color: salmon;
            transform: rotateX(90deg) translateZ(75px);
          }
          .box .bottom {
            background-color: blue;
            transform: rotateX(-90deg) translateZ(75px);
          }
        </style>
    </head>
    <body>
        <div class="box">
            <div class="front">front</div>
            <div class="back">back</div>
            <div class="left">left</div>
            <div class="right">right</div>
            <div class="top">top</div>
            <div class="bottom">bottom</div>
        </div>
    </body>
    </html>
    一个vue的UI库:https://github.com/houfee/light-ui,如果对您有帮助,请star ^-^
  • 相关阅读:
    gc buffer busy/gcs log flush sync与log file sync
    给Oracle年轻的初学者的几点建议
    Android 编程下帧动画在 Activity 启动时自动运行的几种方式
    Android 编程下 Touch 事件的分发和消费机制
    Java 编程下 static 关键字
    Java 编程下 final 关键字
    Android 编程下模拟 HOME 键效果
    Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated ?
    Extjs4 大型项目目录结构重构
    [转]SQLServer 2008 允许远程连接的配置方法
  • 原文地址:https://www.cnblogs.com/houfee/p/9246828.html
Copyright © 2020-2023  润新知