Last active
March 1, 2016 10:36
-
-
Save caryfuk/05c5a99238dfff54f1ac to your computer and use it in GitHub Desktop.
typewriter effect using es6 spread
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
(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