Created
November 4, 2020 14:06
-
-
Save takumifukasawa/4dc346325d855cd3fbe98c9aa77ca11f to your computer and use it in GitHub Desktop.
typescript: reflow dom
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
/** | |
* 強制的にdomのreflowを発火させる | |
* | |
* @export | |
* @param {HTMLElement} dom | |
*/ | |
export function reflow(dom: HTMLElement) { | |
// eslint-disable-next-line no-void | |
void dom.offsetWidth; | |
} | |
/** | |
* 強制的にdomのreflowを発火させつつクラスを付け直す | |
* classNameに紐づくanimationを再度発火させたい時などに使う | |
* | |
* @export | |
* @param {HTMLElement} dom | |
* @param {string} className | |
*/ | |
export function reflowAndReattachClass(dom: HTMLElement, className: string) { | |
dom.classList.remove(className); | |
reflow(dom); | |
dom.classList.add(className); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment