溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果

發(fā)布時間:2022-10-09 17:30:43 來源:億速云 閱讀:129 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要講解了“Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果”吧!

案例效果

Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果

基本樣式

.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:"機(jī)票"
        },
        {
          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:"景點(diǎn)門票"
        }
        ,{
          id:"06",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景點(diǎn)門票"
        }
        ,{
          id:"07",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景點(diǎn)門票"
        }
        ,{
          id:"08",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景點(diǎn)門票"
        }
        ,{
          id:"09",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景點(diǎn)門票"
        }
        ,{
          id:"10",
          imgUrl:"//s.qunarzz.com/homenode/images/touchheader/hotel.png",
          text:"景點(diǎn)門票"
        }
      ],
      swiperOption:{
        //  設(shè)置分頁器
          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) 用來將這些圖片文字 以八個為單位分別拆開 從而實(shí)現(xiàn)最重要的效果

循環(huán)遍歷

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

先遍歷以八個為單位的數(shù)組 然后在遍歷里面的內(nèi)容

感謝各位的閱讀,以上就是“Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Swiper怎么實(shí)現(xiàn)兩行四列輪播圖效果這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI