Last active
December 29, 2019 16:59
-
-
Save gsmartagence/33bf38424b2519a9ffc27941b9fb7774 to your computer and use it in GitHub Desktop.
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
| /** | |
| * onElementReady.js | |
| * @param {string} element - selector string | |
| */ | |
| const onElementReady = element => ( | |
| new Promise((resolve) => { | |
| const waitForElement = () => { | |
| const $element = document.querySelector(element) | |
| if ($element) { | |
| resolve($element) | |
| } else { | |
| window.requestAnimationFrame(waitForElement) | |
| } | |
| } | |
| waitForElement() | |
| }) | |
| ) | |
| export default onElementReady |
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
| { | |
| "name": "onElementReady.js", | |
| "version": "0.1.0" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment