今天就跟大家聊聊有關(guān)微信小程序中怎么自定義一個(gè)輪播圖,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
首先當(dāng)然是要禁用掉(直接刪掉)swiper屬性indicator-dots,再用view組件模擬dots,對(duì)應(yīng)的代碼如下:
<view class="swiper-container"> <swiper autoplay="auto" interval="5000" duration="500" current="{{swiperCurrent}}" bindchange="swiperChange" class="swiper"> <block wx:for="{{slider}}" wx:key="unique"> <swiper-item> <image src="{{item.picUrl}}" class="img"></image> </swiper-item> </block> </swiper> <view class="dots"> <block wx:for="{{slider}}" wx:key="unique"> <view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view> </block> </view> </view>
然后是wxss代碼:
swiper-container{ position: relative; } .swiper-container .swiper{ height: 300rpx; } .swiper-container .swiper .img{ width: 100%; height: 100%; } .swiper-container .dots{ position: absolute; left: 0; right: 0; bottom: 20rpx; display: flex; justify-content: center; } .swiper-container .dots .dot{ margin: 0 8rpx; width: 14rpx; height: 14rpx; background: #fff; border-radius: 8rpx; transition: all .6s; } .swiper-container .dots .dot.active{ width: 24rpx; background: #f80; }
再對(duì)swiper的bindchange屬性綁定對(duì)應(yīng)的事件:
Page({ data: { slider: [ {picUrl: '../../images/T003R720x288M000000rVobR3xG73f.jpg'}, {picUrl: '../../images/T003R720x288M000000j6Tax0WLWhD.jpg'}, {picUrl: '../../images/T003R720x288M000000a4LLK2VXxvj.jpg'}, ], swiperCurrent: 0, }, swiperChange: function(e){ this.setData({ swiperCurrent: e.detail.current }) } })
看完上述內(nèi)容,你們對(duì)微信小程序中怎么自定義一個(gè)輪播圖有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
當(dāng)前題目:微信小程序中怎么自定義一個(gè)輪播圖-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)于:http://chinadenli.net/article24/cehoce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站改版、面包屑導(dǎo)航、App開(kāi)發(fā)、品牌網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容