Created
July 8, 2015 03:14
-
-
Save anonymous/93132e3dd846127742c6 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/dawirodedo
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
<!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> |
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
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; | |
} |
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
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