Briefly describe how WeChat applets meet the various needs of gestures

Source: Internet
Author: User
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)


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}]
  • Real machine effect

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.

  • Conclusion

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 event

Touch-triggered events include "touchstart", "touchmove", "touchend", and "touchcancel ".

  • Store data

[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!

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: 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.