标签:efault button focus comm doc screen mon height null
XX.ontouchstart = function(){ startTime =Date.now(); }; XX.ontouchend = function(){ pre.innerHTML += (‘ontouchend : ‘ + (Date.now() - startTime) + ‘\n‘); }; XX.onclick = function(){ pre.innerHTML += (‘click : ‘ + (Date.now() - startTime)); }
if (‘addEventListener‘ in document) { document.addEventListener(‘DOMContentLoaded‘, function() { FastClick.attach(document.body); }, false); } //优先兼容AMD方式 if (typeof define === ‘function‘ && typeof define.amd === ‘object‘ && define.amd) { define(function() { return FastClick; }); } else if (typeof module !== ‘undefined‘ && module.exports) { //兼容commonJs风格 module.exports = FastClick.attach; module.exports.FastClick = FastClick; } else { //最后兼容原生Js window.FastClick = FastClick; }
//391-450:onTouchStart FastClick.prototype.onTouchStart = function(event) { //tapDelay默认300毫秒,点击时间差小于300毫秒,则阻止事件再次触发,阻止短时间内双击的问题 if ((event.timeStamp - this.lastClickTime) < this.tapDelay) { event.preventDefault(); } } //521-610:onTouchEnd if (!this.needsClick(targetElement)) { // 如果这不是一个需要使用原生click的元素,则屏蔽原生事件,避免触发两次click event.preventDefault(); // 触发一次模拟的click this.sendClick(targetElement, event); } //294-309:sendClick(核心方法) //这个事件会在onTouchEnd中用到,经过一系列的判断,符合条件,调用这个模拟事件 FastClick.prototype.sendClick = function(targetElement, event) { var clickEvent, touch; //创建一个鼠标事件 clickEvent = document.createEvent(‘MouseEvents‘); //初始化鼠标事件 clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); //触发这个事件 targetElement.dispatchEvent(clickEvent); };
//trigger single tap after 250ms of inactivity else { touchTimeout = setTimeout(function(){ touchTimeout = null if (touch.el) touch.el.trigger(‘singleTap‘) touch = {} }, 250) }
标签:efault button focus comm doc screen mon height null
原文地址:http://www.cnblogs.com/chenlogin/p/7493791.html