Last active
January 23, 2018 15:39
-
-
Save DeMoorJasper/305ec3f7a6ffcfd82e691ce49de1a935 to your computer and use it in GitHub Desktop.
TerminalTyper
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
const BLOCK_CHAR = '█'; | |
let blockChar = `${BLOCK_CHAR}`; | |
function updateTerminal(content) { | |
document.getElementById('terminal').innerHTML = content; | |
} | |
function flickerBlock() { | |
if (blockChar.length > 0) { | |
blockChar = ""; | |
} else { | |
blockChar = `${BLOCK_CHAR}`; | |
} | |
} | |
function writeText(text, content, count) { | |
if (content.lastIndexOf(BLOCK_CHAR) > 0) { | |
content = content.substring(0, content.lastIndexOf(BLOCK_CHAR)); | |
} | |
content += text[count] + blockChar; | |
updateTerminal(content); | |
window.setTimeout(() => { | |
flickerBlock(); | |
writeText(text, content, count + 1); | |
}, 50); | |
} | |
document.addEventListener("DOMContentLoaded", function(event) { | |
const text = document.getElementById('someText').value; | |
writeText(text, "", 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment