Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save reynaldobarrosjr/6a7882373376a1a4d0c01113537b57f6 to your computer and use it in GitHub Desktop.
I'm trying to iterate dinamically - with n timers... could you help me?
<!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 timers = new Array(n)
for (var i = 0; i < n; i++) {
timers[i] = new Timer();
timers[i].start();
timers[i].addEventListener('secondsUpdated', function (e) {
var local = '#arrayexample'+i;
local = local + ' .values';
$(local).html(timers[0].getTimeValues().toString());
$('#arrayexample1').html(timers[2].getTimeValues().toString());
});
}
return timers;
}
makeTimers(3);
});
</script>
</head>
<body>
<div id="arrayexample1">
<span>Timer 1</span>
<h1><div class="values"></div></h1>
</div>
<div id="arrayexample2">
<span>Timer 2</span>
<h1><div class="values"></div></h1>
</div>
<div id="arrayexample3">
<span>Timer 3</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