怎么用Swiper实现两行四列轮播图效果

本篇内容主要讲解“怎么用Swiper实现两行四列轮播图效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用Swiper实现两行四列轮播图效果”吧!

你所需要的网站建设服务,我们均能行业靠前的水平为你提供.标准是产品质量的保证,主要从事网站设计、成都网站制作、企业网站建设、手机网站开发、网页设计、高端网站设计、网页制作、做网站、建网站。创新互联拥有实力坚强的技术研发团队及素养的视觉设计专才。

基本样式

.icons{
  width:100%;
  overflow: hidden;
}
.icons-item{
  width: 25%;
  height: 0;
  padding-bottom: 25%;
  float: left;
}
.icons-item img{
  width: 1.1rem;
  height: 1.1rem;
  display: block;
  margin: 0 auto;
  padding-top: .2rem;
}
.icons-item p{
  margin-top: .1rem;
  font-size: .28rem;
  text-align: center;
  color: #212121;
}

所需文件

<script type="text/javascript">
export default {
  data(){
    return {
      swiperOption:{},
      iconsList:[
        {
          id:"01",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"酒店"
        },
        {
          id:"02",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/flight.png",
          text:"机票"
        },
        {
          id:"03",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/train.png",
          text:"火车票"
        },
        {
          id:"04",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/package.png",
          text:"度假"
        }
        ,{
          id:"05",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
        ,{
          id:"06",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
        ,{
          id:"07",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
        ,{
          id:"08",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
        ,{
          id:"09",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
        ,{
          id:"10",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景点门票"
        }
      ],
      swiperOption:{
        //  设置分页器
          pagination: {
            el: '.swiper-pagination',
          }
        }
      }
  },
  computed:{
    page(){
      let pages = [];
      this.iconsList.forEach((item,index)=>{
        let idx = Math.floor(index/8)
        if(!pages[idx]) pages[idx] =[];
        pages[idx].push(item)
      })
      return pages
    }
  }
}
</script>

需要注意的是 let idx = Math.floor(index/8) if(!pages[idx]) pages[idx] =[]; pages[idx].push(item) 用来将这些图片文字 以八个为单位分别拆开 从而实现最重要的效果

循环遍历

<div class="icons">
    <swiper ref="mySwiper" :options="swiperOption">
          <swiper-slide v-for='item in page' :key='item.id'>
            <div v-for="page in item" :key="page.id"  class="icons-item">
              <img :src="page.imgUrl">
              <p>{{page.text}}</p>
            </div>
          </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>

先遍历以八个为单位的数组 然后在遍历里面的内容

到此,相信大家对“怎么用Swiper实现两行四列轮播图效果”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

文章标题:怎么用Swiper实现两行四列轮播图效果
网站网址:https://www.cdcxhl.com/article10/jgppgo.html

成都网站建设公司_创新互联,为您提供面包屑导航网站排名静态网站虚拟主机域名注册

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设