Last active
December 18, 2015 03:19
-
-
Save seantunwin/5717006 to your computer and use it in GitHub Desktop.
This is the original script that compelled me to make a modular version in order to be reusable - https://github.com/seantunwin/chardelay.js | View the project: http://seantunwin.github.io/chardelay.js
This file contains hidden or 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
| /** | |
| * This is the original script that compelled me to make a modular version in order to be reusable | |
| * - Repo: https://github.com/seantunwin/chardelay.js | |
| * - View the project: http://seantunwin.github.io/chardelay.js | |
| **/ | |
| /* Set Array */ | |
| var arr = [1,2,3,4]; | |
| /* Create <p> element */ | |
| var el = document.createElement('p'); | |
| /* Write text inside <p> tag */ | |
| function writeIt(y) { | |
| el.innerHTML += arr[y] + '<br />'; | |
| } | |
| /* Initializer */ | |
| function init() { | |
| /* Set Timeout Interval */ | |
| var time = 1000; | |
| /* Attach <p> tag to document */ | |
| document.body.appendChild(el); | |
| /* Loop through Array */ | |
| for (var i = 0; i < arr.length; i++) { | |
| /* Anonymous IIFE passing vars i and time */ | |
| (function(x, t){ | |
| /* Invoke delay */ | |
| setTimeout(function(){ | |
| /* Call write function */ | |
| writeIt(x); | |
| },x * time); /* multiply to keep consistant interval on each loop*/ | |
| })(i, time); | |
| } | |
| } | |
| /* Start */ | |
| init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment