DOM 相关

UIEvent.detail

The UIEvent.detail read-only property, when non-zero, provides the current (or next, depending on the event) click count.

For click or dblclick events, UIEvent.detail is the current click count.

For mousedown or mouseup events, UIEvent.detail is 1 plus the current click count.

For all other UIEvent objects, UIEvent.detail is always zero.

移动端点击,触发click事件存在300ms延迟

在十几年前,当时的网页基本上都是为PC设备所设计的,没有什么移动端适配的概念,导致字体看起来非常小,阅读困难。 为了处理这种情况,苹果的工程师们想了各种应对方案,其中最为出名的,当属双击缩放(double tap to zoom)。通过双击,在放大比例和原始比例之间进行切换。 如果判断用户是点击还是双击呢?苹果的逻辑如下: 在用户点击完此处第一次后,如果300ms内没有在此处进行第二次点击,就认为是一个纯点击操作。 这就是300ms延迟的来源,浏览器通过300ms的时间间隔猜测你的行为意图,试图分辨你是想单击还是双击。 解决办法: 现在已经不会有这种事啦,无需 fastclick 用原生 click 就好 Chrome 32+ on Android with width=device-width in the viewport meta tag doesn't have a 300ms delay.

html
1
<meta name="viewport" content="width=device-width, initial-scale=1"/>

Same goes for Chrome on Android (all versions) with user-scalable=no in the viewport meta tag. But be aware that user-scalable=no also disables pinch zooming, which may be an accessibility concern.

For IE11+, you can use touch-action: manipulation; to disable double-tap-to-zoom on certain elements (like links and buttons). For IE10 use -ms-touch-action: manipulation.