美文网首页
小程序自定义双击事件

小程序自定义双击事件

作者: 前端来入坑 | 来源:发表于2019-07-17 20:59 被阅读0次
//js
......
let timer = null;
Page({
       data: {
        startTime: 0,
        clickNum: 0
      },
      doubleClick: function(e) {
        let that = this;
        let curTime = e.timeStamp;
        let startTime = this.data.startTime;
        if(startTime == 0){
          that.setData({
            startTime: curTime
          })
         timer = setTimeout(function(){
            that.resetClick();
            if(that.data.clickNum == 1){
              console.log("双击执行事件");
              that.setData({
                startTime: 0,
                clickNum: 0
              })
            }else{
              console.log("单击执行事件");
            }
            clearTimeout(timer);
          },300);
        }else{
          if(curTime - startTime < 300){
            this.setData({
              clickNum: 1
            })
          }
        }
      },
      resetClick: function(){
        let that = this;
        if (that.data.clickNum == 0) { 
          this.setData({
            startTime: 0,
            clickNum: 0
          })
        }
      },
})
......

使用

//wxml
<view catchtap="doubleClick"></view>

相关文章

  • 小程序自定义双击事件

    使用

  • android_自定义多击事件

    自定义双击事件 点击事件:在控件上按下,离开,有瞬间的停留。 双击事件:在单位时间内,双击。 多击事件:在单位时间...

  • javascript笔记10

    事件处理程序 焦点事件 鼠标事件-单击与双击 鼠标事件-mouserover/mouserout/mousedow...

  • 小程序零散知识

    无法在小程序的事件中直接传参,需要通过自定义属性来传参,然后在事件源中获取自定义属性 引入wxss时,用@impo...

  • Lesson10 双击事件和键盘检测

    双击事件(这个地方,泛型的知识需要再巩固下) 键盘按键事件 事件类型是直接调用的事件处理程序是需要new的

  • Android 多次点击事件的触发方法

    Android中经常有自定义的点击事件,但大多数都只是单击或者长按事件.本篇文章对于双击事件提供两种方法: 老土的...

  • 双击事件

    有些时候我们会遇到双击事件,如何设置双击事件。 在你的点击事件里写下一下判断 System.arraycopy(d...

  • 双击事件

    一、原理 1、布尔值 2、setTimeout() 二、实现代码 html: css: JavaScript: 三...

  • Android双击事件实现

    双击退出应用 双击响应事件 利用Handler控制点击事件

  • 锦囊24:凸显量级超屌的图片云PPT

    步骤: 1. 下载小程序:shapecollage3.1.0.0.exe 双击安装 2. 打开小程序,...

网友评论

      本文标题:小程序自定义双击事件

      本文链接:https://www.haomeiwen.com/subject/ehthlctx.html