Last active
August 29, 2015 14:21
-
-
Save jeffskelton3/4459220379c65928ed45 to your computer and use it in GitHub Desktop.
Simple timer (for a friend)
This file contains 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
<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> |
This file contains 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
$(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