Skip to content

Instantly share code, notes, and snippets.

@brettbartylla
Created September 9, 2017 22:22
Show Gist options
  • Save brettbartylla/3c2cbb10fd6d2eb1462d24e28f0090ff to your computer and use it in GitHub Desktop.
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!
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