欢迎光临,了解微信小程序开发,就上易用通!

小程序极速实战开发《三》swiper滑块视图容器

发布:2018-01-25 16:40浏览: 来源:网络 作者:tianshu

组件说明:
  • 滑块视图容器,用于展示图片,可以通过用户拖拽和设置自动切换属性控制图片的切换

组件用法:
小程序极速实战开发《三》swiper滑块视图容器(图1)

wxml

  1. <swiper indicator-dots="{{indicatorDots}}"
  2.   autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
  3.   <block wx:for="{{imgUrls}}">
  4.     <swiper-item>
  5.       <image src="{{item}}" class="slide-image" width="355" height="150"/>
  6.     </swiper-item>
  7.   </block>
  8. </swiper>
  9. <button bindtap="changeIndicatorDots"> indicator-dots </button>
  10. <button bindtap="changeAutoplay"> autoplay </button>
  11. <slider bindchange="intervalChange" show-value min="500" max="2000"/> interval
  12. <slider bindchange="durationChange" show-value min="1000" max="10000"/> duration


js

  1. page({
  2.   data: {
  3.     imgUrls: [
  4.       'https://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
  5.       'https://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
  6.       'https://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
  7.     ],
  8.     indicatorDots: false,
  9.     autoplay: false,
  10.     interval: 5000,
  11.     duration: 1000
  12.   },
  13.   changeIndicatorDots: function(e) {
  14.     this.setData({
  15.       indicatorDots: !this.data.indicatorDots
  16.     })
  17.   },
  18.   changeAutoplay: function(e) {
  19.     this.setData({
  20.       autoplay: !this.data.autoplay
  21.     })
  22.   },
  23.   intervalChange: function(e) {
  24.     this.setData({
  25.       interval: e.detail.value
  26.     })
  27.   },
  28.   durationChange: function(e) {
  29.     this.setData({
  30.       duration: e.detail.value
  31.     })
  32.   }
  33. })
wxss

  1. .swiper-item{
  2.     display: block;
  3.     height: 150px;
  4. }

主要属性:

  • 设置界面的内容样式,用于wxml

属性
类型
默认值
描述
indicator-dots
Boolean
false
是否显示面板指示点
autoplay
Boolean
false
是否自动切换
current
Number
0
当前所在页面的 index
interval
Number
5000
自动切换时间间隔
duration
Number
1000
滑动动画时长
bindchange
EventHandle
 
current 改变时会触发 change 事件,event.detail = {current: current}





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。