13518219792

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

创新互联百度小程序教程:swiper 滑块视图容器

swiper 滑块视图容器

解释:滑块视图容器。内部只允许使用 swiper-item 组件描述滑块内容,否则会导致未定义的行为。

创新互联公司从2013年开始,先为上蔡等服务建站,上蔡等地企业,进行企业商务咨询服务。为上蔡企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

属性说明

indicator-dots

Boolean

false

是否显示面板指示点

indicator-color

Color

rgba(0, 0, 0, .3)

指示点颜色

indicator-active-color

Color

#333

当前选中的指示点颜色

autoplay

Boolean

false

是否自动切换

current

Number

0

当前所在页面的 index

current-item-id

String

当前所在滑块的 item-id ,不能与 current 被同时指定

1.11
低版本请做兼容性处理

interval

Number

5000

自动切换时间间隔(单位:ms)

duration

Number

500

滑动动画时长(单位:ms)

circular

Boolean

false

是否采用衔接滑动

vertical

Boolean

false

滑动方向是否为纵向

previous-margin

String

“0px”

前边距,可用于露出前一项的一小部分,支持 px 和 rpx

1.11
低版本请做兼容性处理

next-margin

String

“0px”

后边距,可用于露出后一项的一小部分,支持 px 和 rpx

1.11
低版本请做兼容性处理

display-multiple-items

Number

1

同时显示的滑块数量

1.11
低版本请做兼容性处理

bindchange

EventHandle

current 改变时会触发 change 事件,event.detail = {current: current, source: source}

bindanimationfinish

EventHandle

动画结束时会触发 animationfinish 事件,event.detail 同上

1.11
低版本请做兼容性处理

属性名类型默认值必填说明最低版本
-
-
-
-
-
-
-
-
-
-

change 事件 source 返回值

change 事件中的 source 字段,表示触发 change 事件的原因,可能值如下:

autoplay

自动播放导致的 swiper 切换

touch

用户滑动导致的 swiper 切换

“”

其他原因将返回空字符串

说明

示例

跳转编辑工具

在开发者工具中打开

在 WEB IDE 中打开

扫码体验

代码示例

请使用百度APP扫码

代码示例 1:

 
 
 
  1. class="swiper"
  2. indicator-dots="{{switchIndicateStatus}}"
  3. indicator-color="rgba(0,0,0,0.30)"
  4. indicator-active-color="#fff"
  5. autoplay="{{switchAutoPlayStatus}}"
  6. current="0"
  7. current-item-id="0"
  8. interval="{{autoPlayInterval}}"
  9. duration="{{switchDuration}}"
  10. circular="true"
  11. vertical="{{switchVerticalStatus}}"
  12. previous-margin="0px"
  13. next-margin="0px"
  14. display-multiple-items="1"
  15. bind:change="swiperChange"
  16. bind:animationfinish="animationfinish">
  17. s-for="item in swiperList"
  18. item-id="{{itemId}}"
  19. class="{{item.className}}">
  20. {{item.value}}
  21. 指示点
  22. class="init-switch"
  23. checked="{{switchIndicateStatus}}"
  24. bind:change="switchIndicate">
  25. 自动切换
  26. checked="{{switchAutoPlayStatus}}"
  27. bind:change="switchAutoPlay"
  28. class="init-switch">
  29. 纵向滑动
  30. checked="{{switchVerticalStatus}}"
  31. bind:change="switchVertical"
  32. class="init-switch">
  33. 滑块切换时长
  34. {{switchDuration}}ms
  35. class="slider"
  36. min="300"
  37. max="1500"
  38. value="{{switchDuration}}"
  39. bind:change="changeSwitchDuration">
  40. 自动切换时间间隔
  41. {{autoPlayInterval}}ms
  42. class="slider"
  43. min="1000"
  44. max="5000"
  45. value="{{autoPlayInterval}}"
  46. bind:change="changeAutoPlayInterval">

设计指南

建议滑块视图数量控制在 2-5 个。
建议滑块切换时长不低于 500ms ,自动切换时间间隔不高于 5000ms 。

代码示例 2:自定义底部切换圆点

 
 
 
  1. 自定义底部切换圆点
  2. class="swiper-custom"
  3. autoplay="auto"
  4. interval="3000"
  5. duration="500"
  6. current="{{swiperCurrent}}"
  7. bindchange="swiperChangeCustom">

代码示例 3:模拟 tabs 组件功能

 
 
 
  1. 模拟 tabs 组件功能
  2. 全部
  3. 服务通知
  4. 系统通知
  5. 评论
  6. 其他
  7. 我是全部
  8. 我是服务通知
  9. 我是系统通知
  10. 我是评论
  11. 我是其他

Bug & Tip

常见问题

Q:swiper 的面板指示点能自定义样式吗?

A:参见属性说明,可以去掉 dot 显示之后,自己定义 dot 样式。具体代码可参见上方代码示例 2 。


当前标题:创新互联百度小程序教程:swiper 滑块视图容器
文章URL:http://cdbrznjsb.com/article/cocsigo.html
  • 网站建设专属方案

  • 网站定制化设计

  • 7X24小时服务

  • N对管家服务

让你的专属顾问为你服务