微信小程序的双击事件

index.js

 1 Page({
 2 data: {
 3 starTime: 0,
 4 ClickNum: 0,
 5 show:false
 6 },
 7 //点击事件
 8 myClick: function (e) {
 9 var that = this
10 var curTime = e.timeStamp;
11 var starTime= this.data.starTime;
12 if (that.data.starTime === 0) {
13 this.setData({
14 starTime: curTime
15 })
16 setTimeout(function () {
17 that.resetClick();
18 if (that.data.ClickNum === 1) {
19 // 双击执行事件区
20 that.setData({
21 starTime: 0,
22 ClickNum: 0,
23 show:!that.data.show
24 })
25 
26 }
27 }, 300)
28 // 300为双击的时间间隔
29 } else {
30 if (curTime - starTime< 300) {
31 this.setData({
32 ClickNum: 1
33 })
34 }
35 }
36 },
37 // 单击重置
38 resetClick: function () {
39 if (this.data.ClickNum === 0) {
40 this.setData({
41 starTime: 0,
42 ClickNum: 0
43 })
44 }
45 }
46 
47 })

 

indx.wxml

<view>
<buttontype="primary"bindtap="myClick">双击事件</button>

<view wx:if="{{show}}">
双击事件
</view>
</view>

 

 

新手求喷~

 

posted @ 2018-04-16 13:05  邱小健  阅读(315)  评论(0编辑  收藏  举报