How can applets meet the various needs of gestures,
Gestures are very important for the operation experience of mobile phone users, especially for some results! In order to achieve some effects of gestures, we often use a wide range of applications such as canvas and interaction. today we mainly look at how small program gestures are implemented. We will introduce the implementation of small program gestures from the following two aspects.
On: single touch point and multi-touch point: let's see the gesture data and multi-touch point support of the applet.
Next: write the wxGesture parsing class: resolution left-slide, right-slide, up-slide, down and expand (next article)
Demo
To check whether the applet supports multiple fingers, you need to use touchstart, touchmove, and touchend.
[AppleScript]View plain text Copy code
// index.wxml
[AppleScript]View plain text Copy code
//index.jstouchstartFn: function(event){ console.log(event); }, touchmoveFn: function(event){ console.log(event); // console.log("move: PageX:"+ event.changedTouches[0].pageX); }, touchendFn: function(event){ console.log(event); // console.log("move: PageX:"+ event.changedTouches[0].pageX); }
First, for single-touch and multi-touch points
Official Document: changedTouches: the data format of changedTouches is the same as that of touches. Indicates the changed touch points, such as touchstart, touchmove, and touchcancel ).
[AppleScript]View plain text Copy code
"changedTouches":[{ "identifier":0, "pageX":53, "pageY":14, "clientX":53, "clientY":14}]
After the above Demo is implemented, the simulator cannot see the data of multiple touch points, so you need a real machine to test.
Check the log information of the real machine.
In changedTouches, the touch point data is stored sequentially, so the applet itself supports multi-touch gestures.
Imagine: Since the gesture of a applet supports multi-touch and relevant paths can be obtained, it is also feasible to calculate the related paths.
Scenario: Multi-touch interaction, finger drawing, etc.
Save touch point data
In order to be able to analyze the path of a touch point, at least simple gestures, such as left, right, up, and down, we need to save all the data of the path.
Touch-triggered events include "touchstart", "touchmove", "touchend", and "touchcancel ".
[AppleScript]View plain text Copy code
Var _ wxChanges = []; var _ wxGestureDone = false; const _ wxGestureStatus = ["touchstart", "touchmove", "touchend", "touchcancel"]; // Collection path function g (e) {if (e. type = "touchstart") {_ wxChanges = []; _ wxGestureDone = false;} if (! _ WxGestureDone) {_ wxChanges. push (e); if (e. type = "touchend") {_ wxGestureDone = true;} else if (e. type = "touchcancel") {_ wxChanges = []; _ wxGestureDone = true ;}}}
The above is a brief description of how the applet meets the various needs of gesture. For more information, see other related articles in the first PHP community!