[移动端新特性] Passive Event Listeners
Passive Event Listeners 这个东西其实有一段时间了,关注 2016 Google I/O 的 Mobile Talk 的同学应该有些印象。
1、它有什么用?
A new feature in the DOM spec that enable developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners.
Developers can annotate touch and wheel listeners with {passive: true} to indicate that they will never invoke preventDefault.
提高页面的滑动流畅度。
如何使用:
function handler () {
console.log('DDFE');
}
document.addEventListener('mousewheel', handler, {passive: true})
其实变化就是:前端 DOM 中常用常考的 addEventListener 的第三个参数:之前都是 true | false