zoukankan      html  css  js  c++  java
  • 小程序踩坑记——长按与点击事件冲突

    对于同一控件同时设置bindtap和bindlongtap,会发现长按时先出现bindlongtap的事件,然后触发点击事件。

    通过测试,我们发现,小程序中事件执行的顺序是
    点击:touchstart → touchend → tap
    长按 touchstart → longtap → touchend → tap

    处理方法:

    // wxml
    <view bindtouchstart="bindTouchStart" bindtouchend="bindTouchEnd" bindlongtap="bingLongTap" bindtap="bindTap">蹂躏我</view>
    // js
    bindTouchStart: function(e) {
        this.startTime = e.timeStamp;
    }
    bindTouchEnd: function(e) {
        this.endTime = e.timeStamp;
    }
    bindTap: function(e) {
        if(this.endTime  - this.startTime < 350) {
            console.log("点击")
        }
    }
    bingLongTap: function(e) {
        console.log("长按");
    }

    这样通过时间来判断,可以一定程度上解决这个问题。

    参考了文章《小程序踩坑记——长按与点击事件冲突》

  • 相关阅读:
    算法——基础
    递归函数
    docker常用命令
    vue——计算属性和侦听器
    vue——指令系统
    vue——介绍和使用
    webpack、babel模块、模块化
    Nodejs介绍及npm工具使用
    ECMAScript 6简介
    easyui(入门)
  • 原文地址:https://www.cnblogs.com/lguow/p/10239933.html
Copyright © 2011-2022 走看看