Last active
June 9, 2019 14:35
-
-
Save akhmadkresna/168253303a8b83fec98fe73f8f587f0b to your computer and use it in GitHub Desktop.
css/js typewriter
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
<html> | |
<head> | |
<link href="style.css" rel="stylesheet" type="text/css"/> | |
</head> | |
<body> | |
<div id="typedtext"></div> | |
<script src="script.js"></script> | |
</body> | |
</html> |
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
// set up text to print, each item in array is new line | |
var aText = new Array( | |
"Somebody or something using your keyboard" | |
); | |
var iSpeed = 100; // time delay of print out | |
var iIndex = 0; // start printing array at this posision | |
var iArrLength = aText[0].length; // the length of the text array | |
var iScrollAt = 20; // start scrolling up at this many lines | |
var iTextPos = 0; // initialise text position | |
var sContents = ''; // initialise contents variable | |
var iRow; // initialise current row | |
function typewriter() | |
{ | |
sContents = ' '; | |
iRow = Math.max(0, iIndex-iScrollAt); | |
var destination = document.getElementById("typedtext"); | |
while ( iRow < iIndex ) { | |
sContents += aText[iRow++] + '<br />'; | |
} | |
destination.innerHTML = sContents + aText[iIndex].substring(0, iTextPos) + "_"; | |
if ( iTextPos++ == iArrLength ) { | |
iTextPos = 0; | |
iIndex++; | |
if ( iIndex != aText.length ) { | |
iArrLength = aText[iIndex].length; | |
setTimeout("typewriter()", 500); | |
} | |
} else { | |
setTimeout("typewriter()", iSpeed); | |
} | |
} | |
typewriter(); |
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
body { | |
font-family: monospace; | |
font-size:30px; | |
margin: 10px 50px; | |
letter-spacing: 6px; | |
font-weight: bold; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment