-
-
Save oirodolfo/a55bfc6f136f12d7a4a611e43c190340 to your computer and use it in GitHub Desktop.
update height with request animation frame
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
| updateHeight(isOpen) { | |
| this.lastRAF && cancelAnimationFrame(this.lastRAF); | |
| if (isOpen) { | |
| this.lastRAF = requestAnimationFrame(() => { | |
| // read: | |
| const height =`${this.contentEl.scrollHeight}px`; | |
| this.lastRAF = requestAnimationFrame(() => { | |
| // write in a different frame: | |
| this.containerEl.style.height = height; | |
| this.lastRAF = null; | |
| }); | |
| }); | |
| } else { | |
| this.containerEl.style.height = '0px'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment