在处理浏览器事件时,我开始将Safari的touchEvents应用于移动设备.我发现addEventListener
个条件句堆积如山.This project can't use JQuery.
标准事件侦听器:
/* option 1 */
window.addEventListener('mousemove', this.mouseMoveHandler, false);
window.addEventListener('touchmove', this.mouseMoveHandler, false);
/* option 2, only enables the required event */
var isTouchEnabled = window.Touch || false;
window.addEventListener(isTouchEnabled ? 'touchmove' : 'mousemove', this.mouseMoveHandler, false);
jQuery的bind
允许多个事件,如下所示:
$(window).bind('mousemove touchmove', function(e) {
//do something;
});
Is there a way to combine the two event listeners as in the JQuery example?例:
window.addEventListener('mousemove touchmove', this.mouseMoveHandler, false);
如有任何建议或小贴士,我们将不胜感激!