Encapsulation of mobile-side tap events

Source: Internet
Author: User

Encapsulation of mobile-side tap events

/* Encapsulate tap */cc. tap = function (dom, callback) {/** requires that the touchmove event not be triggered * and the response speed is faster than click */if (dom & typeof dom = 'object ') {var isMove = false; var startTime = 0; dom. addEventListener ('touchstart', function (e) {// console. log ('touchstart'); // console. time ('tap');/* record the current time of the parameter "tap" */startTime = Date. now () ;}); dom. addEventListener ('touchmove ', function (e) {// console. log ('touchmove '); isMove = true;}); d Om. addEventListener ('touchend', function (e) {// console. log ('touchend'); // console. timeEnd ('tap ') /* print the time when the tap parameter was last recorded * // * determine whether the tap response time is 150 */if (! IsMove & (Date. now ()-startTime) <150) {/* Call callback */callback & callback (e);}/* reset parameter */isMove = false; startTime = 0 ;});}}

The reason for encapsulation is that the click event has a delay.

Related Article

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.