Home WeChat Applet Mini Program Development 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

Aug 21, 2018 pm 05:12 PM

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.

1

2

3

4

5

6

7

<button

bindtouchstart="handleTouchStart"

bindtouchend="handleTouchEnd"

bindlongpress="handleLongPress"

bindtap="handleClick">

点击/长按</button>

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

Copy after login

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("长按"); 

},

Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)