Skip to content

Instantly share code, notes, and snippets.

@goldsamantha
Created June 30, 2015 15:25
Show Gist options
  • Save goldsamantha/cb37265848213d9c3ad2 to your computer and use it in GitHub Desktop.
Save goldsamantha/cb37265848213d9c3ad2 to your computer and use it in GitHub Desktop.
Synchronous Typer
<!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