Skip to content

Instantly share code, notes, and snippets.

@reynaldobarrosjr
Last active May 9, 2018 20:38
Show Gist options
  • Select an option

  • Save reynaldobarrosjr/d3064484c248a7c41e10dfba53beaa71 to your computer and use it in GitHub Desktop.

Select an option

Save reynaldobarrosjr/d3064484c248a7c41e10dfba53beaa71 to your computer and use it in GitHub Desktop.
Trying to do a dinamic array of timers.
<!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';
setInterval(function(){ $('#callbackExample0 .values').html(timer[0].getTimeValues().toString()); }, 1000);
setInterval(function(){ $('#callbackExample1 .values').html(timer[1].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>
@albert-gonzalez
Copy link
Copy Markdown

Hi!

change local = '#callbackExample'+i; with var local = '#callbackExample'+i;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment