Last active
June 22, 2021 08:10
-
-
Save mauskin/eddd0cd822b9daf4c07414a98f09a198 to your computer and use it in GitHub Desktop.
Runs a callback on next click and prevents anything else from happening. Helpful for dismissing full viewport banners by clicking anywhere.
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
function doOnNextClickButNothingElse(callback) { | |
window.addEventListener( | |
"click", | |
function (event) { | |
event.stopPropagation(); | |
callback(); | |
}, | |
{ | |
capture: true, | |
once: true | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment