微信小程序中轮播的使用和绑定事件

轮播组件

轮播组件可以让内容在水平方向上进行轮播展示,非常适合于展示图片、广告等内容。在微信小程序中,轮播组件是通过 和 组合来实现的。

组件
组件是轮播容器,用于包裹多个轮播项。

属性:
indicator-dots:是否显示指示点,默认为 false。
autoplay:是否自动切换,默认为 false。
interval:自动切换时间间隔,单位为毫秒,默认为 5000。
circular:是否采用衔接滑动,默认为 false。
indicator-color:指示点颜色。
indicator-active-color:当前选中的指示点颜色。
组件
组件是轮播项,放置在 组件中,每个 组件代表一张轮播内容。

示例:

<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" circular="{{circular}}" indicator-color="rgba(255, 255, 255, 0.6)" indicator-active-color="#ffffff">
  <swiper-item>
    <image src="/images/slide1.jpg" mode="aspectFill"></image>
  </swiper-item>
  <swiper-item>
    <image src="/images/slide2.jpg" mode="aspectFill"></image>
  </swiper-item>
  <swiper-item>
    <image src="/images/slide3.jpg" mode="aspectFill"></image>
  </swiper-item>
</swiper>

事件绑定

1.事件绑定方式
微信小程序提供了两种事件绑定方式:bind 和 catch。

bind:绑定的事件将冒泡,可以阻止事件向上冒泡。
catch:绑定的事件不会冒泡,可以阻止事件向上冒泡。
2. 事件类型
微信小程序支持的事件类型包括但不限于:

点击事件:bindtap、catchtap
长按事件:bindlongpress、catchlongpress
触摸事件:bindtouchstart、bindtouchmove、bindtouchend、bindtouchcancel、catchtouchstart、catchtouchmove、catchtouchend、catchtouchcancel
表单相关事件:bindinput、bindchange、bindsubmit、bindreset
动画相关事件:bindanimationstart、bindanimationiteration、bindanimationend
3. 事件对象
在事件处理函数中,可以通过 event 对象获取触发事件的相关信息,例如触发事件的组件、触摸点的坐标等。

常用的 event 对象属性包括:

currentTarget:触发事件的组件
target:当前组件
detail:额外信息,例如触摸事件的坐标等

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值