微信小程序中点击事件与长按事件的代码实现实例

why 241 2024-08-05

本篇文章给大家带来的内容是关于微信小程序实例:点击事件和长按事件的代码实现,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

微信小程序中点击事件与长按事件的代码实现实例

1

2

3

4

5

6

7

<button

bindtouchstart="handleTouchStart"

bindtouchend="handleTouchEnd"

bindlongpress="handleLongPress"

bindtap="handleClick">

点击/长按</button>

<!-- button 可以换成view-->

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

//touch start

handleTouchStart: function(e) {   

    this.startTime = e.timeStamp;   

    //console.log(" startTime = " + e.timeStamp); 

}, 

 

//touch end

handleTouchEnd: function(e) {   

    this.endTime = e.timeStamp;   

    //console.log(" endTime = " + e.timeStamp); 

}, 

 

handleClick: function(e) {   

    //console.log("endTime - startTime = " + (this.endTime - this.startTime));   

    if (this.endTime - this.startTime < 350) {     

    console.log("点击");   

    

}, 

 

handleLongPress: function(e) {   

//console.log("endTime - startTime = " + (this.endTime - this.startTime));

console.log("长按"); 

},

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:小程序客服发送图片信息的实现代码与实例分析
下一篇:小程序里授权相册问题的有效解决办法及代码示例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~