Skip to content

Instantly share code, notes, and snippets.

@fuale
Created July 17, 2019 18:38
Show Gist options
  • Save fuale/489945e0d99cdcb95e069e158ae6821a to your computer and use it in GitHub Desktop.
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.
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