189 8069 5689

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

  • swiper 滑块视图容器
    • 属性说明
      • change 事件 source 返回值
    • 示例
      • 代码示例 1:
      • 代码示例 2:自定义底部切换圆点
      • 代码示例 3:模拟 tabs 组件功能
    • Bug & Tip
    • 常见问题
      • Q: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:

    • SWAN
    • JS
    • CSS
     
     
     
    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:自定义底部切换圆点

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

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

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

    Bug & Tip

    • Tip:如果在 bindchange 的事件回调函数中使用 setData 改变 current 值,则会导致 setData 被重复调用,因而通常情况下请在改变 current 值前检测 source 字段来判断是否是由于用户触摸引起的。
    • Tip:组件内部只可放置 swiper-item 组件,否则会导致未定义的行为。

    常见问题

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

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


    分享名称:创新互联百度小程序教程:swiper 滑块视图容器
    本文URL:http://cdxtjz.cn/article/cocsigo.html

    联系我们

    您好HELLO!
    感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们, 我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
    • 电话:028- 86922220 18980695689
    • 商务合作邮箱:631063699@qq.com
    • 合作QQ: 532337155
    • 成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼

    小谭建站工作室

    成都小谭网站建设公司拥有多年以上互联网从业经验的团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。 我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,小谭建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!

    小谭观点

    相对传统的成都网站建设公司而言,小谭是互联网中的网站品牌策划,我们精于企业品牌与互联网相结合的整体战略服务。
    我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。