立方體輪播圖(3d輪播圖)

2021-6-10    前端達人


<!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>

  <style>

    * {

      margin: 0;

      padding: 0;

      list-style: none;

    }

    html {

      height: 100%;

    }

    .container {

      width: 400px;

      margin: 200px auto;

      height: 100px;

      position: relative;

    }

    .box {

      width: 100px;

      height: 100px;

      position: absolute;

      float: left;

    }

    #rigth {

      background-color: rgba(0, 0, 0, 0.3);

      position: absolute;

      right: 0px;

      top: 50%;

      transform: translateY(-50%);

    }

    #left {

      position: absolute;

      left: 0px;

      background-color: rgba(0, 0, 0, 0.3);

      top: 50%;

      transform: translateY(-50%);

    }

    span:hover {

      cursor: pointer;

      color: red;

    }


    ul {

      width: 100px;

      height: 100px;

      transform-style: preserve-3d;

      float: left;

      transition: all 1s;

    }

    .top {

      background-color: red;

      transform: translateY(50px) rotateX(-90deg);

      transform: translateY(50px) rotateX(-90deg);

      background: url('./image/4.jpg') no-repeat;

    }

    .footer {

      transform: translateY(-50px) rotateX(90deg);

      background: url('./image/2.jpg') no-repeat;

    }

    .left {

      transform: translateX(50px) rotateY(90deg)

    }

    .rigth {

      background-color: yellow;

      transform: translateX(-50px) rotateY(-90deg);

    }

    .Front {

      background-color: pink;

      transform: translateZ(50px);

      background: url('./image/1.jpeg') no-repeat;

    }

    .behind {

      background-color: blue;

      transform: translateZ(-50px) rotateX(-180deg);

      background: url('./image/3.jpg') no-repeat;

    }

    /* 前 */

    .container ul:nth-child(2) .Front {

      background-position: -100px 0;

    }

    .container ul:nth-child(3) .Front {

      background-position: -200px 0;

    }

    .container ul:nth-child(4) .Front {

      background-position: -300px 0;

    }

    /* 底部 */

    .container ul:nth-child(2) .footer {

      background-position: -100px 0;

    }

    .container ul:nth-child(3) .footer {

      background-position: -200px 0;

    }

    .container ul:nth-child(4) .footer {

      background-position: -300px 0;

    }

    /* 后面 */

    .container ul:nth-child(2) .behind {

      background-position: -100px 0;

    }

    .container ul:nth-child(3) .behind {

      background-position: -200px 0;

    }

    .container ul:nth-child(4) .behind {

      background-position: -300px 0;

    }

    /* 上面 */

    .container ul:nth-child(2) .top {

      background-position: -100px 0;

    }

    .container ul:nth-child(3) .top {

      background-position: -200px 0;

    }

    .container ul:nth-child(4) .top {

      background-position: -300px 0;

    }

  </style>

</head>

<body>

  <div class="container">

    <ul>

      <li class="box top"></li>

      <li class="box footer"></li>

      <li class="box left"></li>

      <li class="box rigth"></li>

      <li class="box Front"></li>

      <li class="box behind"></li>

    </ul>

    <ul>

      <li class="box top"></li>

      <li class="box footer"></li>

      <li class="box left"></li>

      <li class="box rigth"></li>

      <li class="box Front"></li>

      <li class="box behind"></li>

    </ul>

    <ul>

      <li class="box top"></li>

      <li class="box footer"></li>

      <li class="box left"></li>

      <li class="box rigth"></li>

      <li class="box Front"></li>

      <li class="box behind"></li>

    </ul>

    <ul>

      <li class="box top"></li>

      <li class="box footer"></li>

      <li class="box left"></li>

      <li class="box rigth"></li>

      <li class="box Front"></li>

      <li class="box behind"></li>

    </ul>

    <span id="rigth">下張</span>

    <span href="JavaScript:;" id="left">上張</span>

  </div>

</body>

<script>

  var rigth = document.getElementById("rigth")

  var left = document.getElementById("left")

  var ul = document.querySelectorAll(".container ul")

  var index = 0

  var flags = false

  rigth.onclick = function () {

    if (flags == false) {

      flags = true

      index++

      for (var i = 0; i < ul.length; i++) {

        ul[i].style.transform = "rotateX(" + index * 90 + "deg)"

        ul[i].style.transitionDelay = "" + i * 0.3 + "s"

      }

      setTimeout(function () {

        flags = false

      }, 2000)

    }

  }

  left.onclick = function () {

    if (flags == false) {

      flags = true

      index--

      for (var i = 0; i < ul.length; i++) {

        ul[i].style.transform = "rotateX(" + index * 90 + "deg)"

        ul[i].style.transitionDelay = "" + i * 0.3 + "s"

      }

      setTimeout(function () {

        flags = false

      }, 2000)

    }

  }

</script>

</html>



作者:yuanzhuang

鏈接:https://www.jianshu.com/p/10c90c482795

來源:簡書

藍藍設計建立了UI設計分享群,每天會分享國內外的一些優(yōu)秀設計,如果有興趣的話,可以進入一起成長學習,請掃碼藍小助,報下信息,藍小助會請您入群。歡迎您加入噢~~希望得到建議咨詢、商務合作,也請與我們聯(lián)系。

截屏2021-05-13 上午11.41.03.png


分享此文一切功德,皆悉回向給文章原作者及眾讀者.
免責聲明:藍藍設計尊重原作者,文章的版權歸原作者。如涉及版權問題,請及時與我們取得聯(lián)系,我們立即更正或刪除。

藍藍設計www.yvirxh.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業(yè)提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網(wǎng)站建設 、平面設計服務


日歷

鏈接

個人資料

藍藍設計的小編 http://www.yvirxh.cn

存檔