3D立方体图册

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3D立方体图册</title>
    <style>
      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      body {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        background: #f5f5f5;
      }
      .box {
        position: relative;
        width: 240px;
        height: 300px;
        transform-style: preserve-3d;
        transform: perspective(1000px) rotateY(180deg);
        transition: 1.5s;
      }
      .box::before {
        content: "";
        position: absolute;
        width: 240px;
        height: 240px;
        background: #2225;
        transform: translateY(240px) rotateX(90deg) scale(1.1);
        filter: blur(40px);
      }
      .card {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 300px;
        background: linear-gradient(90deg, #ddd, #eee);
        transform-origin: center;
        transform: rotateY(calc(var(--i) * 90deg)) translateZ(120px);
      }
      .img-box {
        width: 100%;
        height: 240px;
        text-align: center;
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
      .img-box h2 {
        color: red;
      }
      .img-box span {
        color: purple;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="box">
        <div class="card" style="--i: 1">
          <div class="img-box">
            <img src="../assets/img/公孙离.jpg" alt="" srcset="" />
            <h2>公孙离</h2>
            <span>射手</span>
          </div>
        </div>
        <div class="card" style="--i: 2">
          <div class="img-box">
            <img src="../assets/img/宫本武藏.jpg" alt="" srcset="" />
            <h2>宫本武藏</h2>
            <span>战士</span>
          </div>
        </div>
        <div class="card" style="--i: 3">
          <div class="img-box">
            <img src="../assets/img/诸葛亮.jpg" alt="" srcset="" />
            <h2>诸葛亮</h2>
            <span>法师</span>
          </div>
        </div>
        <div class="card" style="--i: 4">
          <div class="img-box">
            <img src="../assets/img/赵云.jpg" alt="" srcset="" />
            <h2>赵云</h2>
            <span>刺客</span>
          </div>
        </div>
      </div>
    </div>
  </body>
  <script>
    const box = document.querySelector(".box");
    let isMoving = false;

    function handleMouseMove(event) {
      if (!isMoving) {
        isMoving = true;
        requestAnimationFrame(() => {
          const boxWidth = box.offsetWidth;
          const boxHeight = box.offsetHeight;
          const mouseX = event.clientX - box.getBoundingClientRect().left;
          const mouseY = event.clientY - box.getBoundingClientRect().top;
          const rotateY = (mouseX / boxWidth - 0.5) * 60; // 通过鼠标位置计算 Y 轴旋转角度
          const rotateX = (0.5 - mouseY / boxHeight) * 60; // 通过鼠标位置计算 X 轴旋转角度

          box.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
          isMoving = false;
        });
      }
    }

    box.addEventListener("mousemove", handleMouseMove);
  </script>
</html>
在这里插入代码片
相关推荐
bin915341 分钟前
(文后附完整代码)html+css+javascript 弓箭射击游戏项目分析
前端·javascript·css·游戏·html·前端开发
CG_MAGIC1 小时前
多软件协同工作流:ZBrush+SP+Blender角色资产全流程解析
3d·blender·zbrush·建模教程·渲云渲染·渲云
修己xj2 小时前
CSS魔法:对话生成器与奔驰骏马的创意实现
前端·css
觉醒大王2 小时前
如何整理文献阅读笔记? (精读与泛读)
前端·css·笔记·深度学习·自然语言处理·html·学习方法
Ulyanov3 小时前
Impress.js深度解析
开发语言·前端·javascript·css3·impress.js
小小码农Come on5 小时前
QPushButton QSS(一):按钮常用qss
前端·javascript·css·qt5
苯酸氨酰糖化物6 小时前
HTML+CSS学信网学籍学历查询页面-支持任意修改内容信息
前端·css3·html5·娱乐
新启航-光学3D测量6 小时前
飞机发动机叶片的光学三维扫描测量逆向-激光三维扫描仪
科技·3d·制造
新启航光学频率梳6 小时前
地铁齿轮箱润滑油道孔深光学3D轮廓测量-激光频率梳3D轮廓技术
科技·3d·制造
Sheldon一蓑烟雨任平生6 小时前
Sass 星空(Sass + keyframes 实现星空动画)
前端·css·vue3·sass·keyframes