Home > Article > WeChat Applet > WeChat Mini Program Example: Code Implementation of Click Events and Long Press Events
The content of this article is about WeChat applet examples: code implementation of click events and long press events. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
<button bindtouchstart="handleTouchStart" bindtouchend="handleTouchEnd" bindlongpress="handleLongPress" bindtap="handleClick"> 点击/长按</button> <!-- button 可以换成view-->
//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("长按"); },
Related recommendations:
How to clear the default styles of buttons and scroll bars in mini programs (code)
json in WeChat mini programs Introduction to configuration configuration methods (with code)
The above is the detailed content of WeChat Mini Program Example: Code Implementation of Click Events and Long Press Events. For more information, please follow other related articles on the PHP Chinese website!