Last active
May 23, 2019 12:15
-
-
Save danielt69/ae99ec480461d59cff1635178195e41e to your computer and use it in GitHub Desktop.
a better (performance) event listener
This file contains 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
/* Feature detection */ | |
var passiveIfSupported = false; | |
try { | |
window.addEventListener("test", null, Object.defineProperty({}, "passive", { get: function() { passiveIfSupported = { passive: true }; } })); | |
} catch(err) {} | |
window.addEventListener('scroll', function(event) { | |
/* do something */ | |
// can't use event.preventDefault(); | |
console.count('scroll'); | |
}, passiveIfSupported ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment