Created
June 19, 2017 13:43
-
-
Save radist2s/ab7840b327b1d68cd13a26ed2f2c03d3 to your computer and use it in GitHub Desktop.
Passive events support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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