本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)層疊輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
wxml:
<view class="banner-swiper"> <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" current='{{swiperCurrent}}' indicator-color="{{beforeColor}}" indicator-active-color="{{afterColor}}" circular='{{circular}}' previous-margin="{{previousmargin}}" next-margin="{{nextmargin}}" bindchange="swiperChange" > <block wx:for="{{arr}}" wx:key="key"> <swiper-item> <image src="{{item.images}}" class="slide-image{{index == swiperCurrent ? ' active' : ''}}" bindchange="chuangEvent" id="{{index}}"></image> </swiper-item> </block> </swiper> </view>
wxss:
.banner-swiper { width: 100%; height: 500rpx; overflow: hidden; } swiper { display: block; height: 500rpx; position: relative; } .slide-image { width: 96%; display: block; margin: 0 auto; height: 450rpx; margin-top:25rpx; } .active{ margin-top:0rpx; height: 500rpx; }
js:
Page({ data: { //輪播圖 swiperCurrent:1, arr: [{ images: 'images/1.jpg' }, { images: 'images/5.jpg' }, { images: 'images/3.jpg' }, { images: 'images/4.jpg' } ] indicatorDots: true, autoplay: true, interval: 2000, duration: 1000, circular: true, beforeColor: "white",//指示點(diǎn)顏色 afterColor: "coral",//當(dāng)前選中的指示點(diǎn)顏色 previousmargin:'30px',//前邊距 nextmargin:'30px',//后邊距 }, //輪播圖的切換事件 swiperChange: function (e) { console.log(e.detail.current); this.setData({ swiperCurrent: e.detail.current //獲取當(dāng)前輪播圖片的下標(biāo) }) }, //滑動(dòng)圖片切換 chuangEvent: function (e) { this.setData({ swiperCurrent: e.currentTarget.id }) }, })
效果圖:
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com