Javascript Timer
Timer para hacer llamadas de actualización.
by Yolanda Robles
HTML
<button class="restart">restart</button>
<button class="pause">pause</button>
<span class="time">1</span>
JavaScript
var count = 0;
var unSegundo = 1000;
var medioSegundo = 500;
$time = $('.time');
counter = function () {
count++;
// Para que se reinicie
/*if (count > 15) {
count = 1;
}*/
$time.html(count);
// Cada 1 segundo
timer = setTimeout(function () {
counter();
}, medioSegundo);
};
counter();
$('button').on('click', function () {
clearTimeout(timer);
if ($(this).hasClass('restart')) {
count = 0;
paused = false;
counter();
} else {
paused = !paused;
if (!paused) {
counter();
}
}
});