Last active
December 17, 2015 03:59
-
-
Save carlsednaoui/5547573 to your computer and use it in GitHub Desktop.
Simple JS timer created for GA class.
This file contains hidden or 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
// $(document).ready(function() { | |
// var counter = timer(90); // time in seconds | |
// var status = "active"; | |
// function timer(count) { | |
// var intervalID = setInterval(function() { | |
// $('.timer').text(status + ": " + count); | |
// count -= 1; | |
// if (count <= 0 && status == "active") { | |
// clearInterval(intervalID); | |
// status = "rest"; | |
// timer(30); // time in seconds | |
// } else if (count <= 0 && status == "rest") { | |
// clearInterval(intervalID); | |
// status = "active"; | |
// timer(90); // time in seconds | |
// } | |
// }, 1000); | |
// } | |
// }); | |
$(document).ready(function() { | |
(function timer(count, status) { | |
var intervalID = setInterval(function() { | |
document.querySelectorAll('.timer')[0].innerHTML = (status + ": " + Math.floor(count/ 60) + ":" + (count % 60)); | |
count -= 1; | |
if (count <= 0 && status == "active") { | |
clearInterval(intervalID); | |
timer(30, "rest"); | |
} else if (count <= 0 && status == "rest") { | |
clearInterval(intervalID); | |
timer(150, "active"); | |
} | |
}, 1000); | |
})(10, "active"); | |
}); | |
// Requires the page to have something like this: <p class="timer">Ready?</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment