微信小程序使用swiper組件實現(xiàn)層疊輪播圖
更新時間:2021年04月19日 09:30:30 作者:瑪咪啞哄
這篇文章主要為大家詳細介紹了微信小程序使用swiper組件實現(xiàn)層疊輪播圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序實現(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",//指示點顏色 afterColor: "coral",//當前選中的指示點顏色 previousmargin:'30px',//前邊距 nextmargin:'30px',//后邊距 }, //輪播圖的切換事件 swiperChange: function (e) { console.log(e.detail.current); this.setData({ swiperCurrent: e.detail.current //獲取當前輪播圖片的下標 }) }, //滑動圖片切換 chuangEvent: function (e) { this.setData({ swiperCurrent: e.currentTarget.id }) }, })
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JS實現(xiàn)網(wǎng)頁Div層Clone拖拽效果
這篇文章主要介紹了JS實現(xiàn)網(wǎng)頁Div層Clone拖拽效果,涉及JavaScript響應鼠標事件動態(tài)改變頁面元素位置屬性及層級屬性的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09使用JSON.parse將json字符串轉換成json對象的時候會出錯
使用JSON.parse將json字符串轉換成json對象的時候會出錯,主要是雙引號,回車換行等影響明顯,左尖括號和右尖括號也會導致顯示問題2014-09-09