Skip to content

Instantly share code, notes, and snippets.

@if540
Created April 24, 2019 06:43
Show Gist options
  • Save if540/d534694e7b499855fcd5b608a5b2651c to your computer and use it in GitHub Desktop.
Save if540/d534694e7b499855fcd5b608a5b2651c to your computer and use it in GitHub Desktop.
iscroll 被動事件偵聽器以提升滾動性能(ie not support)
/**
* iscroll 被動事件偵聽器以提升滾動性能(ie not support)
* source code : https://github.com/cubiq/iscroll/blob/master/demos/demoUtils.js
* MDN : https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener#option%E6%94%AF%E6%8C%81%E7%9A%84%E5%AE%89%E5%85%A8%E6%A3%80%E6%B5%8B
* passive google article : https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners?hl=zh-tw
*/
function isPassive () {
var passiveSupported = false
try {
var options = Object.defineProperty({}, 'passive', {
get: function () {
passiveSupported = true
}
})
window.addEventListener('test', null, options)
} catch (err) { }
return passiveSupported
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment