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!