微信小程序滑塊視圖容器swiper,微信小程序swiper實(shí)例
swiper
滑塊視圖容器。
| 屬性名 | 類型 | 默認(rèn)值 | 說明 | 最低版本 |
|---|---|---|---|---|
| indicator-dots | Boolean | false | 是否顯示面板指示點(diǎn) | |
| indicator-color | Color | rgba(0, 0, 0, .3) | 指示點(diǎn)顏色 | 1.1.0 |
| indicator-active-color | Color | #000000 | 當(dāng)前選中的指示點(diǎn)顏色 | 1.1.0 |
| autoplay | Boolean | false | 是否自動切換 | |
| current | Number | 0 | 當(dāng)前所在頁面的 index | |
| interval | Number | 5000 | 自動切換時間間隔 | |
| duration | Number | 500 | 滑動動畫時長 | |
| circular | Boolean | false | 是否采用銜接滑動 | |
| vertical | Boolean | false | 滑動方向是否為縱向 | |
| bindchange | EventHandle | current 改變時會觸發(fā) change 事件,event.detail = {current: current, source: source} |
從公共庫v1.4.0開始,change事件返回detail中包含一個source字段,表示導(dǎo)致變更的原因,可能值如下:
-
autoplay自動播放導(dǎo)致swiper變化; -
touch用戶劃動引起swiper變化; - 其他原因?qū)⒂每兆址硎尽?/li>
注意:其中只可放置<swiper-item/>組件,否則會導(dǎo)致未定義的行為。
swiper-item
僅可放置在<swiper/>組件中,寬高自動設(shè)置為100%。
示例代碼:
<swiper indicator-dots="{{indicatorDots}}"
autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<block wx:for="{{imgUrls}}">
<swiper-item>
<image src="{{item}}" class="slide-image" width="355" height="150"/>
</swiper-item>
</block>
</swiper>
<button bindtap="changeIndicatorDots"> indicator-dots </button>
<button bindtap="changeAutoplay"> autoplay </button>
<slider bindchange="intervalChange" show-value min="500" max="2000"/> interval
<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: false,
autoplay: false,
interval: 5000,
duration: 1000
},
changeIndicatorDots: function(e) {
this.setData({
indicatorDots: !this.data.indicatorDots
})
},
changeAutoplay: function(e) {
this.setData({
autoplay: !this.data.autoplay
})
},
intervalChange: function(e) {
this.setData({
interval: e.detail.value
})
},
durationChange: function(e) {
this.setData({
duration: e.detail.value
})
}
})
更多微信小程序開發(fā)教程,可以關(guān)注hi小程序。
第二部分:如何開通一個小商店

立即掃碼關(guān)注

多門店/直營/加盟連鎖管理系統(tǒng)