Home  >  Article  >  WeChat Applet  >  WeChat Mini Program Example: Code Implementation of Click Events and Long Press Events

WeChat Mini Program Example: Code Implementation of Click Events and Long Press Events

不言
不言Original
2018-08-21 17:12:486741browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn