微信小程序swiper輪播圖組件使用方法詳解
本文實例為大家分享了微信小程序swiper輪播圖組件的使用,供大家參考,具體內(nèi)容如下
在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: []// 默認數(shù)據(jù)(可以從引用組件處的屬性傳入該屬性值) ? ? } ? }, ? data: { ? ? currentIndex: 0 ?// 初始高亮下標(biāo) ? }, ? methods: { ? ? /* 這里實現(xiàn)控制自定義輪播指示點高亮 */ ? ? 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'], }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于JS中setTimeout()無法調(diào)用帶參函數(shù)問題的解決方法
這篇文章主要介紹了關(guān)于JS中setTimeout()無法調(diào)用帶參函數(shù)問題的解決方法,提供了2種解決方法供大家對比參考,需要的朋友可以參考下2016-06-06JS自動跳轉(zhuǎn)手機移動網(wǎng)頁的實現(xiàn)方法
本文主要介紹了JS自動跳轉(zhuǎn)手機移動網(wǎng)頁的實現(xiàn)方法,可以通過檢查 navigator.userAgent 屬性來識別用戶代理字符串中包含的設(shè)備信息,下面就詳細的來介紹一下具體用法,感興趣的可以了解一下2024-03-03javascript 操作cookies及正確使用cookies的屬性
在 JS(JavaScript) 操作cookies比較復(fù)雜,在 ASP 里面我們只需要知道 cookie 的名稱、cookie 的值就行了,而 JS 里面,我們面對的是 cookie 的字符串,你自己編寫這個字符串寫入客戶端,然后自己解析這個字符串。2009-10-10js實現(xiàn)七夕表白彈幕效果 jQuery實現(xiàn)彈幕技術(shù)
這篇文章主要介紹了js實現(xiàn)七夕表白彈幕效果,jQuery實現(xiàn)彈幕技術(shù),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08微信小程序?qū)崿F(xiàn)動態(tài)列表項的順序加載動畫
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)動態(tài)列表項的順序加載動畫,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-07-07