码迷,mamicode.com
首页 > 其他好文 > 详细

3D轮播图

时间:2018-12-05 18:36:47      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:rgb   flag   com   reserve   function   enter   device   absolute   javascrip   

<!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>
    * {
      padding: 0;
      margin: 0;
      list-style: none;
    }

    .view {
      width: 560px;
      height: 300px;
      margin: 100px auto;
      position: relative;

    }

    ul {
      width: 100%;
      height: 100%;
      transform-style: preserve-3d;
      transform: rotate3d(1, 1, 0, 0deg);
    }

    ul>li {
      width: 20%;
      height: 100%;
      float: left;
      transform-style: preserve-3d;
      position: relative;
      /* 过度效果 */
      transition: transform 0.6s;

    }

    ul>li>span {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
    }

    ul>li>span:nth-of-type(1) {
      background: url("./images/q1.jpg");
      /* 往z轴正方向偏移 */
      transform: translateZ(150px);
    }

    ul>li>span:nth-of-type(2) {
      background: url("./images/q2.jpg");
      transform: translateY(-150px) rotateX(90deg);
    }

    ul>li>span:nth-of-type(3) {
      background: url("./images/q3.jpg");
      transform: translateZ(-150px) rotateX(-180deg);

    }

    ul>li>span:nth-of-type(4) {
      background: url("./images/q4.jpg");
      transform: translateY(150px) rotateX(-90deg);
    }

    ul>li:nth-of-type(2)>span {
      background-position-x: -100%;
    }

    ul>li:nth-of-type(3)>span {
      background-position-x: -200%;
    }

    ul>li:nth-of-type(4)>span {
      background-position-x: -300%;
    }

    ul>li:nth-of-type(5)>span {
      background-position-x: -400%;
    }

    .pre,
    .next {
      width: 40px;
      height: 60px;
      font-size: 40px;
      position: absolute;
      top: 50%;
      text-decoration: none;
      text-align: center;
      line-height: 60px;
      color: #ccc;
      background-color: rgba(0, 0, 0, 0.4);
      transform: translate(0, -50%);
    }

    .pre {
      left: 0;
    }

    .next {
      right: 0;
    }
  </style>
</head>

<body>
  <div class="view">
    <ul>
      <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>

      </li>
      <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>

      </li>
      <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>

      </li>
      <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
      </li>
      <li>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
      </li>
    </ul>
    <a href="javascript:;" class="pre" id="pre">&lt;</a>
    <a href="javascript:;" class="next" id="next">&gt;</a>
  </div>
  <script src="./js/jquery-3.1.0.js"></script>
  <script>
    $(function () {
      var index = 0
      var flag = true;
      //右箭头
      $("#next").on("click", function () {
        if (flag == true) {
          flag = false;
          index--;
          $("li").each(function (key, value) {
            $(this).css({
              "transform": "rotateX(" + (index * 90) + "deg)",
              "transition-delay": (key * 0.2) + "s"
            });
          });
          setTimeout(function () {
            flag = true;
          }, 1000);
        }
      });
      //左箭头
      $("#pre").on("click", function () {
        if (flag == true) {
          flag = false;
          index++;
          $("li").each(function (key, value) {
            $(this).css({
              "transform": "rotateX(" + (index * 90) + "deg)",
              "transition-delay": (key * 0.2) + "s"
            });
          });
          setTimeout(function () {
            flag = true;
          }, 1000)
        }
      })


    })
  </script>
</body>

</html>

技术分享图片

3D轮播图

标签:rgb   flag   com   reserve   function   enter   device   absolute   javascrip   

原文地址:https://www.cnblogs.com/tuziling/p/10072323.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!