微信小程序swiper輪播圖組件使用方法詳解
更新時間:2022年07月07日 09:16:59 作者:In Heaven
這篇文章主要為大家詳細介紹了微信小程序swiper輪播圖組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序swiper輪播圖組件的使用,供大家參考,具體內容如下
在components中新建文件夾swiper
components/swiper/swiper.wxml
<!--components/swiper/swiper.wxml--> <view class="container"> ? ? <swiper class="swiper-box" bind:change="swiperChange" interval="4000" circular autoplay> ? ? ? ? <block wx:for="{{swiperList}}" wx:key="index"> ? ? ? ? ? ? <swiper-item> ? ? ? ? ? ? ? ? <image class="targetImg" src="{{item}}" mode="aspectFill"></image> ? ? ? ? ? ? </swiper-item> ? ? ? ? </block> ? ? </swiper> ? ? <!--重置小圓點的樣式 ?--> ? ? <view class="dots"> ? ? ? ? <view class="dotsBox" style='width:{{(swiperList.length*26+swiperList.length*10) + "rpx"}}'> ? ? ? ? <!-- <view class="dotsBox" style='width:180rpx'> --> ? ? ? ? ? ? <block wx:for="{{swiperList}}" wx:key="index"> ? ? ? ? ? ? ? ? <text class="dot {{index == currentIndex ? 'dot-active' : ''}}"></text> ? ? ? ? ? ? </block> ? ? ? ? </view> ? ? </view> </view>
components/swiper/swiper.js
Component({ ? properties: { ? ? swiperList: { ? ? ? type: Array, ? ? ? value: []// 默認數據(可以從引用組件處的屬性傳入該屬性值) ? ? } ? }, ? data: { ? ? currentIndex: 0 ?// 初始高亮下標 ? }, ? methods: { ? ? /* 這里實現控制自定義輪播指示點高亮 */ ? ? swiperChange(e) { ? ?? ? ? ? this.setData({ ? ? ? ? currentIndex: e.detail.current ? ? ? }) ? ? ? ? ? } ? } })
components/swiper/swiper.wxss
/* components/swiper/swiper.wxss */ .container { ? position: relative; } .swiper-box { ? width: 100%; ? height: 364rpx; } .targetImg { ? width: 100%; ? height: 100%; } /*小圓點 ?*/ .dots { ? width: 100%; ? height: 4rpx; ? display: flex; ? position: absolute; ? bottom: 30rpx; } .dotsBox { ? height: 4rpx; ? display: flex; ? margin: 0 auto; } /*未選中時的小圓點樣式 */ .dot { ? width: 26rpx; ? height: 4rpx; ? border-radius: 2rpx; ? margin-right: 10rpx; ? background-color: #ffffff; ? opacity: 0.4; } /*選中以后的小圓點樣式 ?*/ .dot-active { ? opacity: 1; }
在pages文件中引用
json文件中
{ ? "usingComponents": { ? ? "w-swiper":"/components/swiper/swiper" ? } }
html文件中
<w-swiper swiperList="{{sprList}}" />
js文件中
data:{ ? ? sprList:['/images/img.png','/images/img.png'], }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
關于JS中setTimeout()無法調用帶參函數問題的解決方法
這篇文章主要介紹了關于JS中setTimeout()無法調用帶參函數問題的解決方法,提供了2種解決方法供大家對比參考,需要的朋友可以參考下2016-06-06javascript 操作cookies及正確使用cookies的屬性
在 JS(JavaScript) 操作cookies比較復雜,在 ASP 里面我們只需要知道 cookie 的名稱、cookie 的值就行了,而 JS 里面,我們面對的是 cookie 的字符串,你自己編寫這個字符串寫入客戶端,然后自己解析這個字符串。2009-10-10