Skip to content

Instantly share code, notes, and snippets.

@caryfuk
Last active March 1, 2016 10:36
Show Gist options
  • Save caryfuk/05c5a99238dfff54f1ac to your computer and use it in GitHub Desktop.
Save caryfuk/05c5a99238dfff54f1ac to your computer and use it in GitHub Desktop.
typewriter effect using es6 spread
(function() {
let textNode, elm,
textWrapper = document.getElementById('content'),
text = [...textWrapper.textContent];
// clear content of the node
while(textWrapper.hasChildNodes()) {
textWrapper.removeChild(textWrapper.lastChild);
}
// apply the effect
text.map(
(letter, i) => (
setTimeout(function(){
textNode = document.createTextNode(letter);
elm = document.createElement('span');
elm.appendChild(textNode);
textWrapper.appendChild(elm);
}, 200*i)
)
)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment