Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2015 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/93132e3dd846127742c6 to your computer and use it in GitHub Desktop.
Save anonymous/93132e3dd846127742c6 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/dawirodedo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<style id="jsbin-css">
body, html {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
margin: 0;
padding: 0;
}
@keyframes blinkingRed {
from { background-color: red; }
to { background-color: white; }
}
body.good {
background-color: lightgreen;
}
body.notSoGood {
background-color: yellow;
}
body.bad {
animation: blinkingRed ease-in 1s infinite alternate;
}
body.dead {
animation: blinkingRed 0.25s infinite alternate;
}
time {
margin: auto auto;
font-family: sans-serif;
font-size: 15em;
}
</style>
</head>
<body>
<time></time>
<script id="jsbin-javascript">
var timeElement = document.getElementsByTagName("time")[0];
var startingTime = 2 * 60;
var timeRemaining = startingTime;
function pad2(n) {
n = "" + n;
return "00".slice(n.length) + n;
}
function formatTime(time) {
var h = Math.floor(time / 3600);
var m = Math.floor((time % 3600) / 60);
var s = time % 60;
return pad2(h) + ":" + pad2(m) + ":" + pad2(s);
}
var timeoutId = setInterval(function(){
--timeRemaining;
timeElement.innerText = formatTime(timeRemaining);
if (timeRemaining <= 0) {
clearTimeout(timeoutId);
document.body.className = "dead";
} else if (timeRemaining <= startingTime / 20) {
document.body.className = "bad";
} else if (timeRemaining <= startingTime / 5) {
document.body.className = "notSoGood";
} else {
document.body.className = "good";
}
}, 1000);
</script>
<script id="jsbin-source-css" type="text/css">body, html {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
margin: 0;
padding: 0;
}
@keyframes blinkingRed {
from { background-color: red; }
to { background-color: white; }
}
body.good {
background-color: lightgreen;
}
body.notSoGood {
background-color: yellow;
}
body.bad {
animation: blinkingRed ease-in 1s infinite alternate;
}
body.dead {
animation: blinkingRed 0.25s infinite alternate;
}
time {
margin: auto auto;
font-family: sans-serif;
font-size: 15em;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">var timeElement = document.getElementsByTagName("time")[0];
var startingTime = 2 * 60;
var timeRemaining = startingTime;
function pad2(n) {
n = "" + n;
return "00".slice(n.length) + n;
}
function formatTime(time) {
var h = Math.floor(time / 3600);
var m = Math.floor((time % 3600) / 60);
var s = time % 60;
return pad2(h) + ":" + pad2(m) + ":" + pad2(s);
}
var timeoutId = setInterval(function(){
--timeRemaining;
timeElement.innerText = formatTime(timeRemaining);
if (timeRemaining <= 0) {
clearTimeout(timeoutId);
document.body.className = "dead";
} else if (timeRemaining <= startingTime / 20) {
document.body.className = "bad";
} else if (timeRemaining <= startingTime / 5) {
document.body.className = "notSoGood";
} else {
document.body.className = "good";
}
}, 1000);</script></body>
</html>
body, html {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
margin: 0;
padding: 0;
}
@keyframes blinkingRed {
from { background-color: red; }
to { background-color: white; }
}
body.good {
background-color: lightgreen;
}
body.notSoGood {
background-color: yellow;
}
body.bad {
animation: blinkingRed ease-in 1s infinite alternate;
}
body.dead {
animation: blinkingRed 0.25s infinite alternate;
}
time {
margin: auto auto;
font-family: sans-serif;
font-size: 15em;
}
var timeElement = document.getElementsByTagName("time")[0];
var startingTime = 2 * 60;
var timeRemaining = startingTime;
function pad2(n) {
n = "" + n;
return "00".slice(n.length) + n;
}
function formatTime(time) {
var h = Math.floor(time / 3600);
var m = Math.floor((time % 3600) / 60);
var s = time % 60;
return pad2(h) + ":" + pad2(m) + ":" + pad2(s);
}
var timeoutId = setInterval(function(){
--timeRemaining;
timeElement.innerText = formatTime(timeRemaining);
if (timeRemaining <= 0) {
clearTimeout(timeoutId);
document.body.className = "dead";
} else if (timeRemaining <= startingTime / 20) {
document.body.className = "bad";
} else if (timeRemaining <= startingTime / 5) {
document.body.className = "notSoGood";
} else {
document.body.className = "good";
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment