Created
July 17, 2019 18:38
-
-
Save fuale/489945e0d99cdcb95e069e158ae6821a to your computer and use it in GitHub Desktop.
Gradual reduction of the string. Smooth line reduction. Smooth narrowing of the string.
This file contains 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
export function easeInOutQuad(t) { | |
return t * (2 - t); | |
} | |
/** | |
* Erase symbol one by one | |
* @param {Element} element | |
*/ | |
export function smoothErase(element) { | |
const text = element.innerHTML; | |
const time = () => easeInOutQuad(element.innerHTML.length / text.length) * 60; | |
const frame = () => { | |
if (element.innerHTML.length > 0) { | |
const cur = element.innerHTML; | |
element.innerHTML = cur.slice(0, cur.length - 1); | |
setTimeout(frame, time()); | |
} | |
}; | |
setTimeout(frame, time()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment