小程序连续tap事件设置scroll-view的位置会导致tap事件触发延迟和卡死

博客指出在小程序中,点击view触发tap事件,当该事件仅设置scroll - view属性scroll - into - view或scroll - top所需值时,连续点击两次以上会出现延迟,超过三次时中间点击无法触发,最后一次延迟触发,预期是每次点击都能按时触发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题模块框架类型问题类型API/组件名称终端类型微信版本基础库版本
API 和组件小程序Bugscroll-view客户端6.7.22.23

- 当前 Bug 的表现

    点击view触发tag事件,该事件只设置scroll-view属性scroll-into-view或scroll-top所需的值,连续点击两次以上会出现延迟,根据timeStamp显示至少会多出300,连续点击超过三次,前两次正常触发,中间点击的都无法触发,最后一次延迟触发

 

- 预期表现

    每次点击都能按时触发tag事件

 

- 提供一个最简复现 Demo

js

Page({

 

  data: {

    ids: ["a""b""c""d""e""f"],

    id: 'a',

    idTops: []

  },

 

  onLoad: function (options) {

    var that = this

    var query = wx.createSelectorQuery()

    for (var i = 0; i < that.data.ids.length; i++) {

      query.select('#' + that.data.ids[i]).boundingClientRect()

    }

    query.exec(function (res) {

      var idTops = {}

      for (var i = 0; i < res.length; i++) {

        idTops[res[i].id] = res[i].top

      }

      that.setData({

        idTops: idTops

      })

    })

  },

 

  switchClickEvent: function(e) {

    console.log(e)

    this.setData({

      id: e.currentTarget.dataset.id

    })

  }

 

})

wxml

<view class='container'>

  <view class='left'>

    <view class='category {{id == item ? "category-selected" : ""}}' wx:for='{{ids}}' wx:key bindtap='switchClickEvent' data-id='{{item}}'>ID:{{item}}</view>

  </view>

  <!-- 测试scroll-into-view属性 -->

  <scroll-view class='right' scroll-y scroll-into-view='{{id}}' scroll-top='{{idTops[id]}}'>

    <view id='{{item}}' wx:for='{{ids}}' wx:key style='height: 500px; padding: 30rpx; background: #{{item + item + item}}'>ID:{{item}}</view>

  </scroll-view>

  <!-- 测试scroll-top属性 -->

  <!-- <scroll-view class='right' scroll-y scroll-top='{{idTops[id]}}'>

    <view id='{{item}}' wx:for='{{ids}}' wx:key style='height: 500px; padding: 30rpx; background: #{{item + item + item}}'>ID:{{item}}</view>

  </scroll-view> -->

</view>

wxss

.container {

  display: flex;

  flex-direction: row;

  positionabsolute;

  width100%;

  height100%;

}

.left {

  display: flex;

  flex-direction: column;

  height100%;

  background: whitesmoke;

}

.right {

  height100%;

  flex: 1;

}

.category {

  font-size30rpx;

  line-height30rpx;

  padding30rpx;

  width100rpx;

  color#888;

}

.category-selected {

  backgroundwhite;

  color#333;

  font-weightbold;

}

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Homilier

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值