Sample code for three types of events in WeChat applets

Source: Internet
Author: User
This article mainly introduces three types of event sample code for small programs. This article mainly introduces three types of events in small programs and demonstrates them with code.

There are three main types of Applet events:
1-Click an event

2-double-click the event

3-long press event

A click event consists of touchstart and touchend, and a tap event is triggered after touchend.
(1) click an event

View code

   
  Click me.
 

JS code

mytouchstart: function(e){    console.log(e.timeStamp + '- touch start')},mytouchend: function(e){   console.log(e.timeStamp + '- touch end')},mytap: function(e){    console.log(e.timeStamp + '- tap')}

Here, the bindtouchstart function is used to bind the touch start event, and the bindtouchend function is bound to the event triggered when the touch ends.
And the content of these two event functions can be implemented in js code.

(2) double-click an event

Double-click events are composed of two click events, which are considered as double-click events with an interval of less than Ms. the official documentation does not have double-click events, which must be customized by developers.
View


Click me.

JS code

View code

   
  Click me.
 

JS code

Mytouchstart: function (e) {console. log (e. timeStamp + '-touch start')}, // long press event mylongtap: function (e) {console. log (e. timeStamp + '-long tap')}, console. log (e. timeStamp + '-touch end')}, mytap: function (e) {console. log (e. timeStamp + '-tap ')}


For more articles about sample code for three types of events in small programs, refer to PHP Chinese website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.