Created
March 5, 2020 16:27
-
-
Save litvinovvo/a935d6267ea0e9b5a4be1a6636ef8119 to your computer and use it in GitHub Desktop.
Long task free getboundingClientRect
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 getBoundingClientRect(element) { | |
return new Promise(resolve => { | |
const observer = new IntersectionObserver(([entity]) => { | |
observer.unobserve(element); | |
observer.disconnect(); | |
resolve(entity.boundingClientRect); | |
}); | |
observer.observe(element); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment