Amupu

html3d立体旋转页面代码例子演示

以下是一个简单的 HTML 3D 立体旋转页面的代码示例:


html3d立体旋转页面代码例子演示

<!DOCTYPE html>
<html>
  <head>
    <title>3D立体旋转页面</title>
    <style>
      /* 设置容器 */
      #container {
        width: 400px;
        height: 400px;
        perspective: 800px;
      }
      /* 设置盒子 */
      #box {
        width: 100%;
        height: 100%;
        position: relative;
        transform-style: preserve-3d;
        animation: spin 5s linear infinite;
      }
      /* 设置表面 */
      .surface {
        position: absolute;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        box-shadow: 0px 0px 30px rgba(255, 255, 255, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 50px;
        color: #fff;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
      }
      /* 设置不同的表面的旋转角度 */
      .front {
        transform: translateZ(200px);
      }
      .back {
        transform: translateZ(-200px) rotateY(180deg);
      }
      .left {
        transform: translateX(-200px) rotateY(-90deg);
      }
      .right {
        transform: translateX(200px) rotateY(90deg);
      }
      .top {
        transform: translateY(-200px) rotateX(90deg);
      }
      .bottom {
        transform: translateY(200px) rotateX(-90deg);
      }
      /* 设置旋转动画 */
      @keyframes spin {
        from {
          transform: rotateY(0);
        }
        to {
          transform: rotateY(360deg);
        }
      }
    </style>
  </head>
  <body>
    <div id="container">
      <div id="box">
        <div class="surface front">前面</div>
        <div class="surface back">后面</div>
        <div class="surface left">左面</div>
        <div class="surface right">右面</div>
        <div class="surface top">顶面</div>
        <div class="surface bottom">底面</div>
      </div>
    </div>
  </body>
</html>


代码解释:


- `perspective` 属性设置视距,是让 3D 元素更真实的一个重要属性。

- `transform-style` 属性设置为 `preserve-3d` 表示子元素可以保留 3D 的效果。

- `transform` 属性是控制元素进行 3D 变换的关键属性。

- `translateZ` 用于沿着 z 轴方向移动元素。

- `rotateX`、`rotateY`、`rotateZ` 用于沿着 x、y、z 轴方向旋转元素。

- `animation` 属性用于定义旋转动画的细节。


效果图截图:


搜索
分类最新
    分类最新,为您呈现各领域的最新动态和热点话题。无论您关注科技、财经、创业还是生活,这里都能满足您的需求。我们精选最新文章,提供最新鲜、全面的内容,掌握最新的知识和趋势,保持与时俱进的步伐。
分类热门
    分类热门栏目,汇聚了各类热门话题的精华文章,无论是科技、云计算、生活还是时尚,都能在这里找到最新鲜、最热门的内容。我们精选优质文章,为您呈现一个丰富多彩的信息世界,让您在轻松阅读中领略不同领域的魅力,感受时代的脉搏。
  • 作文热门
  • 情感热门
  • 生活热门
分类猜你喜欢
    分类猜你喜欢栏目,根据您的阅读偏好和兴趣,为您精准推荐热门文章。我们运用智能算法,为您呈现最符合您口味的精彩内容。无论是深度解析、趣味科普还是心灵鸡汤,这里都有您喜欢的文章,让您在阅读中享受乐趣,发现更多精彩。
  • 作文分类!
  • 情感分类!
  • 生活分类!
© Copyright Amupu.Z-Blog.Some Rights Reserved.