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.