基于swiper的两边叠加轮播图

今天有个需求是做轮播图,用的swiper,没有找到合适的两边叠加的,最后终于找到了,搬一下,再改一下大小,我也可以用了,哈哈哈

原文地址:点击进入

注意,swiper插件是4.5版本,比较老的了,新版有更简单的办法

 

下边是我改的,去掉了分页器,下边圆圈,还有把大小改了

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
   <script src="./swiper.min.js"></script>
   <link rel="stylesheet" href="./swiper.min.css">
    <style>
    #certify {
        position: relative;
        /* width: 1200px; */
        width: 300px;

        margin: 0 auto
    }
    #certify .swiper-container {
        /* padding-bottom: 60px; */
    }
    #certify  .swiper-slide {
        width: 110px;
        height: 100px;
        background: #fff;
        box-shadow: 0 4px 15px #ddd;
    }
    #certify  .swiper-slide img{
        display:block;
    }
    #certify .swiper-pagination {
        width: 100%;
        bottom: 10px;
    }
    #certify .swiper-pagination-bullets .swiper-pagination-bullet {
        margin: 0 5px;
        border: 3px solid #fff;
        background-color: #d5d5d5;
        width: 5px;
        height: 5px;
        opacity: 1;
    }
    #certify .swiper-pagination-bullets .swiper-pagination-bullet-active {
        border: 3px solid #00aadc;
        /* background-color: #fff; */
    }
    .pop_lc_logo {
      display: block;
      width: 100px;
    }
/* 
    #certify .swiper-button-prev {
        left: -30px;
        width: 45px;
        height: 45px;
        background: url(../images/wm_button_icon.png) no-repeat;
        background-position: 0 0;
        background-size: 100%;
    }
    #certify .swiper-button-prev:hover {
        background-position: 0 -46px;
        background-size: 100%
    }
    #certify .swiper-button-next {
        right: -30px;
        width: 45px;
        height: 45px;
        background: url(../images/wm_button_icon.png) no-repeat;
        background-position: 0 -93px;
        background-size: 100%;
    }
    #certify .swiper-button-next:hover {
        background-position: 0 -139px;
        background-size: 100%
    } */
</style>

    </style>
  </head>
  <body>
    <div id="certify">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                  <img class="pop_lc_logo" src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png" alt="">
                </div>
                <div class="swiper-slide">
                  <img class="pop_lc_logo" src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png" alt="">
                </div>         <div class="swiper-slide">
                  <img class="pop_lc_logo" src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png" alt="">
                </div>         <div class="swiper-slide">
                  <img class="pop_lc_logo" src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png" alt="">
                </div>         <div class="swiper-slide">
                  <img class="pop_lc_logo" src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png" alt="">
                </div>
            </div>
        </div>
    </div>
  </body>
</html>
<script>
  var certifySwiper = new Swiper("#certify .swiper-container", {
    watchSlidesProgress: true,  
    slidesPerView: "auto",
    centeredSlides: true,
    loop: true,
    autoplay: true,
    loopedSlides: 5,
    autoplay: true,
    // navigation: {
    //   nextEl: ".swiper-button-next",
    //   prevEl: ".swiper-button-prev",
    // },
    // pagination: {
    //   el: ".swiper-pagination",
    //   //clickable :true,
    // },
    on: {
      progress: function (progress) {
        for (i = 0; i < this.slides.length; i++) {
          var slide = this.slides.eq(i);
          var slideProgress = this.slides[i].progress;
          modify = 1;
          if (Math.abs(slideProgress) > 1) {
            modify = (Math.abs(slideProgress) - 1) * 0.3 + 1;
          }
          translate = slideProgress * modify * 40 + "px";
          scale = 1 - Math.abs(slideProgress) / 4;
          zIndex = 999 - Math.abs(Math.round(10 * slideProgress));
          slide.transform("translateX(" + translate + ") scale(" + scale + ")");
          slide.css("zIndex", zIndex);
          slide.css("opacity", 1);
          if (Math.abs(slideProgress) > 3) {
            slide.css("opacity", 0);
          }
        }
      },
      setTransition: function (transition) {
        for (var i = 0; i < this.slides.length; i++) {
          var slide = this.slides.eq(i);
          slide.transition(transition);
        }
      },
    },
  });
</script>

项目是手机端的,用的不是px,还有一份rem的,自动播放关闭,循环关闭

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./swiper.min.js"></script>
    <link rel="stylesheet" href="./swiper.min.css" />
    <style>
      /*轮播图*/
      .swip {
        width: 6.37rem;
        height: 3.6rem;
        /*box-shadow: 0.07rem 0 0.25rem 0*/
        /*rgba(53, 43, 33, 0.16);*/
        /*background-color: blue;*/
        margin-top: 0.45rem;
        margin-bottom: 0.3rem;

        display: flex;
        justify-content: center;
        align-items: center;
      }
      /*轮播图*/
      #certify {
        position: relative;
        width: 6rem;
        margin: 0 auto;
      }
      #certify .swiper-container {
        padding-bottom: 1.2rem;
      }
      #certify .swiper-slide {
        width: 2.2rem;
        height: 2rem;
        /*background: #fff;*/
        /*box-shadow: 0 4px 15px #ddd;*/
      }
      #certify .swiper-slide img {
        display: block;
      }
      #certify .swiper-pagination {
        width: 100%;
        bottom: 0.2rem;
      }
      #certify .swiper-pagination-bullets .swiper-pagination-bullet {
        margin: 0 1rem;
        /*border: 3px solid #fff;*/
        /*background-color: #d5d5d5;*/
        width: 1rem;
        height: 1rem;
        opacity: 1;
      }
      #certify .swiper-pagination-bullets .swiper-pagination-bullet-active {
        border: 0.06rem solid #00aadc;
        /* background-color: #fff; */
      }
      .swiper-slide img {
        display: block;
        width: 3rem;
      }
    </style>
  </head>
  <body>
    <div id="certify">
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide">
            <img
              class="pop_lc_logo"
              src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png"
              alt=""
            />
          </div>
          <div class="swiper-slide">
            <img
              class="pop_lc_logo"
              src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png"
              alt=""
            />
          </div>
          <div class="swiper-slide">
            <img
              class="pop_lc_logo"
              src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png"
              alt=""
            />
          </div>
          <div class="swiper-slide">
            <img
              class="pop_lc_logo"
              src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png"
              alt=""
            />
          </div>
          <div class="swiper-slide">
            <img
              class="pop_lc_logo"
              src="https://m.360buyimg.com/babel/jfs/t1/185179/19/29789/29437/6358e59eE023f01d0/6678e14da2621a01.png"
              alt=""
            />
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

<script>
  var certifySwiper = new Swiper("#certify .swiper-container", {
    watchSlidesProgress: true,
    slidesPerView: "auto",
    centeredSlides: true,
    // loop: true,
    // autoplay: true,
    loopedSlides: 5,
    // autoplay: true,
    initialSlide: 1, //默认第二个

    on: {
      progress: function (progress) {
        for (i = 0; i < this.slides.length; i++) {
          var slide = this.slides.eq(i);
          var slideProgress = this.slides[i].progress;
          modify = 1;
          if (Math.abs(slideProgress) > 1) {
            modify = (Math.abs(slideProgress) - 1) * 0.3 + 1;
          }
          translate = slideProgress * modify * 0.8 + "rem";
          scale = 1 - Math.abs(slideProgress) / 4;
          zIndex = 999 - Math.abs(Math.round(10 * slideProgress));
          slide.transform("translateX(" + translate + ") scale(" + scale + ")");
          slide.css("zIndex", zIndex);
          slide.css("opacity", 1);
          if (Math.abs(slideProgress) > 3) {
            slide.css("opacity", 0);
          }
        }
      },
      setTransition: function (transition) {
        for (var i = 0; i < this.slides.length; i++) {
          var slide = this.slides.eq(i);
          slide.transition(transition);
        }
      },
    },
  });
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值