Blogger Information
Blog 85
fans 0
comment 0
visits 94856
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
微信小程序官方组件展示之视图容器swiper源码
软件事业部
Original
587 people have browsed it

以下将展示微信小程序之视图容器swiper源码官方组件能力,组件样式仅供参考,开发者可根据自身需求定义组件样式,具体属性参数详见小程序开发文档。
功能描述:
滑块视图容器。其中只可放置swiper-item组件,否则会导致未定义的行为。
属性说明:
WebView


Skyline

change事件 source 返回值
从 1.4.0 开始,change事件增加 source字段,表示导致变更的原因,可能值如下:
1.autoplay 自动播放导致 swiper 变化;
2.touch 用户划动引起 swiper 变化;
3.其它原因将用空字符串表示。
Bug & Tip
1.tip: 如果在 bindchange 的事件回调函数中使用 setData 改变 current 值,则有可能导致 setData 被不停地调用,因而通常情况下请在改变 current 值前检测 source 字段来判断是否是由于用户触摸引起。
2.tip: 在 mac 小程序上,若当前组件所在的页面或全局开启了 enablePassiveEvent 配置项,该内置组件可能会出现非预期表现(详情参考 enablePassiveEvent 文档)
示例代码:
JAVASCRIPT

  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'swiper',
  5. path: 'page/component/pages/swiper/swiper'
  6. }
  7. },
  8. data: {
  9. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  10. indicatorDots: true,
  11. vertical: false,
  12. autoplay: false,
  13. interval: 2000,
  14. duration: 500
  15. },
  16. changeIndicatorDots() {
  17. this.setData({
  18. indicatorDots: !this.data.indicatorDots
  19. })
  20. },
  21. changeAutoplay() {
  22. this.setData({
  23. autoplay: !this.data.autoplay
  24. })
  25. },
  26. intervalChange(e) {
  27. this.setData({
  28. interval: e.detail.value
  29. })
  30. },
  31. durationChange(e) {
  32. this.setData({
  33. duration: e.detail.value
  34. })
  35. }
  36. })

WXML:

  1. <view class="container">
  2. <view class="page-body">
  3. <view class="page-section page-section-spacing swiper">
  4. <swiper indicator-dots="{{indicatorDots}}"
  5. autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
  6. <block wx:for="{{background}}" wx:key="*this">
  7. <swiper-item>
  8. <view class="swiper-item {{item}}"></view>
  9. </swiper-item>
  10. </block>
  11. </swiper>
  12. </view>
  13. <view class="page-section" style="margin-top: 40rpx;margin-bottom: 0;">
  14. <view class="weui-cells weui-cells_after-title">
  15. <view class="weui-cell weui-cell_switch">
  16. <view class="weui-cell__bd">指示点</view>
  17. <view class="weui-cell__ft">
  18. <switch checked="{{indicatorDots}}" bindchange="changeIndicatorDots" />
  19. </view>
  20. </view>
  21. <view class="weui-cell weui-cell_switch">
  22. <view class="weui-cell__bd">自动播放</view>
  23. <view class="weui-cell__ft">
  24. <switch checked="{{autoplay}}" bindchange="changeAutoplay" />
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="page-section page-section-spacing">
  30. <view class="page-section-title">
  31. <text>幻灯片切换时长(ms)</text>
  32. <text class="info">{{duration}}</text>
  33. </view>
  34. <slider bindchange="durationChange" value="{{duration}}" min="500" max="2000"/>
  35. <view class="page-section-title">
  36. <text>自动播放间隔时长(ms)</text>
  37. <text class="info">{{interval}}</text>
  38. </view>
  39. <slider bindchange="intervalChange" value="{{interval}}" min="2000" max="10000"/>
  40. </view>
  41. </view>
  42. </view>

版权声明: 本站所有内容均由互联网收集整理、上传,如涉及版权问题,我们第一时间处理。
原文链接地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post