Skip to content

Instantly share code, notes, and snippets.

@radist2s
Created June 19, 2017 13:43
Show Gist options
  • Save radist2s/ab7840b327b1d68cd13a26ed2f2c03d3 to your computer and use it in GitHub Desktop.
Save radist2s/ab7840b327b1d68cd13a26ed2f2c03d3 to your computer and use it in GitHub Desktop.
Passive events support
// https://github.com/Modernizr/Modernizr/issues/1894#issuecomment-198035521
window.passiveEventsSupport = function passiveEventsSupport() {
if (passiveEventsSupport.supportsPassive !== undefined) {
return passiveEventsSupport.supportsPassive
}
var supportsPassive = false
var opts = Object.defineProperty && Object.defineProperty({}, 'passive', {
get: function () {
supportsPassive = true
}
})
document.addEventListener('test', function() {}, opts)
passiveEventsSupport.supportsPassive = supportsPassive
}
// ******
// Using
// Use our detect's results. passive applied if supported, capture will be false either way.
elem.addEventListener('touchstart', fn, passiveEventsSupport() ? { passive: true } : false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment