Skip to content

Instantly share code, notes, and snippets.

@jeffskelton3
Last active August 29, 2015 14:21
Show Gist options
  • Save jeffskelton3/4459220379c65928ed45 to your computer and use it in GitHub Desktop.
Save jeffskelton3/4459220379c65928ed45 to your computer and use it in GitHub Desktop.
Simple timer (for a friend)
<button type='button'
id="startTimer"
class='btn btn-primary'>start timer</button>
<button type='button'
id='stopTimer'
class='btn btn-danger hide'>stop timer</button>
$(function(){
var miliseconds = 1000,
interval = null,
$startTimer = $('#startTimer'),
$stopTimer = $('#stopTimer');
$startTimer.on('click', onStartClick);
$stopTimer.on('click', onStopClick);
function doSomething(){
$('body').append('blah');
}
function startTimer(){
interval = setInterval(doSomething, miliseconds);
}
function stopTimer(){
if(interval){
clearInterval(interval);
}
}
function onStartClick(e){
$stopTimer.removeClass('hide');
$startTimer.addClass('hide');
startTimer();
}
function onStopClick(e){
$startTimer.removeClass('hide');
$stopTimer.addClass('hide');
stopTimer();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment