微信小程序开发 专题
专题目录
您的位置:微信小程序开发 > 微信小程序开发专题 > 微信小程序滑块视图容器 swiper
微信小程序滑块视图容器 swiper
作者:--    发布时间:2019-11-20

滑块视图容器。

属性名类型默认值说明最低版本
indicator-dotsbooleanfalse是否显示面板指示点 
indicator-colorcolorrgba(0, 0, 0, .3)指示点颜色1.1.0
indicator-active-colorcolor#000000当前选中的指示点颜色1.1.0
autoplaybooleanfalse是否自动切换 
currentnumber0当前所在页面的 index 
intervalnumber5000自动切换时间间隔 
durationnumber500滑动动画时长 
circularbooleanfalse是否采用衔接滑动 
verticalbooleanfalse滑动方向是否为纵向 
bindchangeeventhandle current 改变时会触发 change 事件,event.detail = {current: current, source: source}  


从公共库v1.4.0开始,change事件返回detail中包含一个source字段,表示导致变更的原因,可能值如下:

  • autoplay自动播放导致swiper变化;
  • touch用户划动引起swiper变化;
  • 其他原因将用空字符串表示。

注意:其中只可放置<swiper-item/>组件,否则会导致未定义的行为。

swiper-item

仅可放置在<swiper/>组件中,宽高自动设置为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
    })
  }
})
网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册