Swiper如何實(shí)現(xiàn)兩行四列輪播圖效果實(shí)例
案例效果
基本樣式
.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:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"酒店" }, { id:"02", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/flight.png", text:"機(jī)票" }, { id:"03", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/train.png", text:"火車票" }, { id:"04", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/package.png", text:"度假" } ,{ id:"05", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"景點(diǎn)門票" } ,{ id:"06", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"景點(diǎn)門票" } ,{ id:"07", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"景點(diǎn)門票" } ,{ id:"08", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"景點(diǎn)門票" } ,{ id:"09", imgUrl:"http://s.qunarzz.com/homenode/images/touchheader/hotel.png", text:"景點(diǎn)門票" } ,{ id:"10", imgUrl:"http://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) 用來將這些圖片文字 以八個(gè)為單位分別拆開 從而實(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>
先遍歷以八個(gè)為單位的數(shù)組 然后在遍歷里面的內(nèi)容
總結(jié)
到此這篇關(guān)于Swiper如何實(shí)現(xiàn)兩行四列輪播圖效果的文章就介紹到這了,更多相關(guān)Swiper兩行四列輪播圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
防止網(wǎng)站內(nèi)容被拷貝的一些方法與優(yōu)缺點(diǎn)好處與壞處分析
防止網(wǎng)站內(nèi)容被拷貝的一些方法與優(yōu)缺點(diǎn)好處與壞處分析...2007-11-11使用Promise和JavaScript有效處理1000個(gè)請求的方法
在現(xiàn)代Web開發(fā)中,處理高并發(fā)請求是一個(gè)常見的挑戰(zhàn),當(dāng)我們需要從服務(wù)器獲取大量數(shù)據(jù)或執(zhí)行多個(gè)異步任務(wù)時(shí),如何有效地管理請求的并發(fā)性和性能變得至關(guān)重要,本文將介紹如何使用Promise和JavaScript來管理高并發(fā)請求,需要的朋友可以參考下2023-09-09KnockoutJS 3.X API 第四章之?dāng)?shù)據(jù)控制流if綁定和ifnot綁定
這篇文章主要介紹了KnockoutJS 3.X API 第四章之?dāng)?shù)據(jù)控制流if綁定和ifnot綁定的相關(guān)資料,需要的朋友可以參考下2016-10-10JS實(shí)現(xiàn)顯示帶倒影的圖片橫排居中放大展示特效實(shí)例【測試可用】
這篇文章主要介紹了JS實(shí)現(xiàn)顯示帶倒影的圖片橫排居中放大展示功能,可實(shí)現(xiàn)點(diǎn)擊圖片及點(diǎn)擊左右按鈕滑動(dòng)切換的效果,涉及javascript針對鼠標(biāo)事件的響應(yīng)及頁面元素動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-08-08js實(shí)現(xiàn)網(wǎng)頁標(biāo)題欄閃爍提示效果實(shí)例分析
這篇文章主要介紹了js實(shí)現(xiàn)網(wǎng)頁標(biāo)題欄閃爍提示效果的方法,以實(shí)例形式分析了網(wǎng)上比較常見的實(shí)現(xiàn)方法,并對于原理進(jìn)行分析并加以改進(jìn),最后給出了一個(gè)具體的應(yīng)用實(shí)例供大家參考,需要的朋友可以參考下2014-11-11