Created
June 30, 2015 15:25
-
-
Save goldsamantha/cb37265848213d9c3ad2 to your computer and use it in GitHub Desktop.
Synchronous Typer
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>synchronous fiddle</title> | |
</head> | |
<body> | |
<h1 class="init-text"></h1> | |
<script type="text/javascript"> | |
txtElem = document.getElementsByClassName('init-text'); | |
fullText = "I do things synchronously! Woohoo."; | |
console.log(txtElem); | |
var i=-1; | |
var mx = fullText.length; | |
function showText(obj, text){ | |
obj.innerHTML = text +"|"; | |
if (i> mx){ | |
obj.innerHTML = text; | |
// This is where you would clear the interval | |
clearInterval(typer); | |
console.log(document.getElementsByClassName("myForm")); | |
} | |
} | |
//SET INTERVAL FUNCTION | |
var typer = setInterval('showText(txtElem[0], fullText.slice(0,i++))', 55); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment