swiper

Swiper view container

Property

TypeDefaultDescription
indicator-dotsBooleanfalseShow indicator or not.
indicator-colorColorrgba(0, 0, 0, .3)Indicator color.
indicator-active-colorColor#000Color of currently selected indicator.
autoplayBooleanfalseAuto switch or not.
currentNumber0Current page index.
durationNumber500(ms)Swipe animation duration.
intervalNumber5000(ms)Auto switch interval.
circularBooleanfalseEnable infinite swipe or not.
verticalBooleanfalseIs swipe direction vertical or not.
onChangeEventHandleNoTrigger on current change, event.detail = {current, current}.

Swiper-item

Can place in component or not; width and height are automatically set as 100%.

Sceenshot

image

Sample Code

copy
<swiper
  indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}"
  interval="{{interval}}"
>
  <block a:for="{{background}}">
    <swiper-item>
      <view class="swiper-item bc_{{item}}"></view>
    </swiper-item>
  </block>
</swiper>
<view class="btn-area">
  <button class="btn-area-button" type="default" onTap="changeIndicatorDots">indicator-dots</button>
  <button class="btn-area-button" type="default" onTap="changeAutoplay">autoplay</button>
</view>
<slider onChange="intervalChange" value="{{interval}}" show-value min="2000" max="10000"/>
<view class="section__title">interval</view>
copy
Page({
  data: {
    background: ['green', 'red', 'yellow'],
    indicatorDots: true,
    autoplay: false,
    interval: 3000,
  },
  changeIndicatorDots(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },
})