CSS3动画实现立方体 - [例子]

博主个人教程

下面是实现代码 通过CSS3的3D转换来实现一个立方体DEMO


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    body {
      color: white;
      padding: 150px;
      background: rgb(60, 60, 60);
    }

    .container {
      position: relative;
      width: 200px;
      height: 200px;
      transition: 0.5s;
      transform-style: preserve-3d;
    }

    .container div {
      position: absolute;
      border: 1px solid white;
      top: 0;
      width: 200px;
      height: 200px;
    }

    .container div img {
      width: 100%;
      height: 100%;
    }

    .container .top {
      transform: rotateX(90deg) translateZ(100px);
    }

    .container .bottom {
      transform: rotateX(-90deg) translateZ(100px);
    }

    .container .left {
      transform: rotateY(-90deg) translateZ(100px);
    }

    .container .right {
      transform: rotateY(90deg) rotateX(0deg) translateZ(100px);
    }

    .container .front {
      transform: rotateY(0deg) translateZ(100px);
    }

    .container .after {
      transform: rotateY(180deg) translateZ(100px);
    }

    .c_top:checked ~ .container {
      transform: rotateX(-90deg);
    }
    .c_bottom:checked ~ .container {
      transform: rotateX(90deg);
    }
    .c_left:checked ~ .container {
      transform: rotateY(90deg);
    }
    .c_right:checked ~ .container {
      transform: rotateY(-90deg);
    }
    .c_front:checked ~ .container {
      transform: rotateX(0deg);
    }
    .c_after:checked ~ .container {
      transform: rotateY(-180deg);
    }
  </style>
  <body>
    <input type="radio" name="c" class="c_top" /> top
    <input type="radio" name="c" class="c_bottom" /> bottom
    <input type="radio" name="c" class="c_front" /> front
    <input type="radio" name="c" class="c_after" /> after
    <input type="radio" name="c" class="c_left" /> left
    <input type="radio" name="c" class="c_right" /> right <br />
    <br />
    <br />
    <br />
    <br />
    <div class="container">
      <div class="top">
        <img
          src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2967613618,689336435&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
      <div class="bottom">
        <img
          src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3010015630,3017077777&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
      <div class="left">
        <img
          src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3010015630,3017077777&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
      <div class="right">
        <img
          src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3010015630,3017077777&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
      <div class="front">
        <img
          src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=4190671957,611176633&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
      <div class="after">
        <img
          src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=499219047,2605789247&fm=26&gp=0.jpg"
          alt=""
        />
      </div>
    </div>
  </body>
</html>

在线演示地址
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值