WeChat Open Platform

Mini Programs Documentation

swiper

Sliding view container

Attribute name Type Default value Description Minimum version
indicator-dots Boolean false Whether panel indicator dots displayed
indicator-color Color rgba(0, 0, 0, .3) Color of indicator dots {%version('1.1.0')%}
indicator-active-color Color #000000 Color of currently selected indicator dot {%version('1.1.0')%}
autoplay Boolean false Whether to switch automatically
current Number 0 Current page index
interval Number 5000 Automatic switching time interval
duration Number 500 Slide animation duration
circular Boolean false Whether to use cohesive sliding
bindchange EventHandle A change event will be triggered when current changes, event.detail = {current: current}  

Note: Only <swiper-item/> components can be placed in this component, otherwise this will lead to an undefined action.

swiper-item

Can only be placed in the <swiper/> component, height and width are automatically set at 100%.

Sample code:

<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
    })
  }
})