Created
September 9, 2017 22:22
-
-
Save brettbartylla/3c2cbb10fd6d2eb1462d24e28f0090ff to your computer and use it in GitHub Desktop.
Simulates a message bring typed. Sets a div with the id of "typewriter" as the message that equals the string value of the str variable. There is a working example of this at the top of my website!
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
var str = "<h2>Full Stack Development</h2>", | |
i = 0, | |
isTag, | |
text; | |
(function type() { | |
text = str.slice(0, ++i); | |
if (text === str) return; | |
document.getElementById('typewriter').innerHTML = text; | |
var char = text.slice(-1); | |
if( char === '<' ) isTag = true; | |
if( char === '>' ) isTag = false; | |
if (isTag) return type(); | |
setTimeout(type, 150); | |
}()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment