Last active
May 9, 2018 20:53
-
-
Save reynaldobarrosjr/37b7e9947a33a3a939ff154f2e7e178a to your computer and use it in GitHub Desktop.
Creating random timers dinamically
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
| <!DOCTYPE html> | |
| <html lang="en" dir="ltr"> | |
| <head> | |
| <meta charset=""> | |
| <title></title> | |
| <script | |
| src="https://code.jquery.com/jquery-3.3.1.min.js" | |
| integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" | |
| crossorigin="anonymous"></script> | |
| <script src="./node_modules/easytimer/dist/easytimer.min.js"></script> | |
| <script> | |
| $(document).ready(function(){ | |
| function makeTimers(n){ | |
| var timer = new Array(n); | |
| for (var i = 0; i < timer.length; i++) { | |
| timer[i] = new Timer(); | |
| var aleatoryminutes= Math.floor(Math.random() * 20); | |
| console.log(aleatoryminutes); | |
| timer[i].start({startValues: {seconds: aleatoryminutes}}); | |
| var local = '#callbackExample'+i; | |
| local = local + ' .values'; | |
| // i've tried to iterate here - but I got the error - cant read getValues from undefined element // | |
| setInterval(function(){ $('#callbackExample0 .values').html(timer[0].getTimeValues().toString()); }, 1000); | |
| setInterval(function(){ $('#callbackExample1 .values').html(timer[1].getTimeValues().toString()); }, 1000); | |
| setInterval(function(){ $('#callbackExample2 .values').html(timer[2].getTimeValues().toString()); }, 1000); | |
| } | |
| } | |
| makeTimers(4); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="callbackExample0"> | |
| <span>Timer 0</span> | |
| <h1><div class="values"></div></h1> | |
| </div> | |
| <div id="callbackExample1"> | |
| <span>Timer 1</span> | |
| <h1><div class="values"></div></h1> | |
| </div> | |
| <div id="callbackExample2"> | |
| <span>Timer 2</span> | |
| <h1><div class="values"></div></h1> | |
| </div> | |
| <div id="callbackExample3"> | |
| <span>Timer 3</span> | |
| <h1><div class="values"></div></h1> | |
| </div> | |
| <div id="callbackExample4"> | |
| <span>Timer 4</span> | |
| <h1><div class="values"></div></h1> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment