Skip to content

Instantly share code, notes, and snippets.

@basyura
Created July 14, 2011 14:50
Show Gist options
  • Save basyura/1082597 to your computer and use it in GitHub Desktop.
Save basyura/1082597 to your computer and use it in GitHub Desktop.
timer その 1
<html>
<head>
<script>
var timer_ = null;
var start_ = null;
var background_ = null;
function initialize() {
background_ = document.body.background;
}
function start() {
start_ = Date.now();
timer_ = setInterval(down , 100);
}
function stop() {
clearTimeout(timer_);
}
function reset() {
clearTimeout(timer_);
document.getElementById("timer").innerHTML = 120;
}
function down() {
var diff = Date.now() - start_;
var txt = parseInt(((120000 - diff) / 1000).toString().split("\.")[0],10);
if (txt == 0) {
stop();
return;
}
if (document.body.background != background_) {
document.body.background = background_;
back_flg_ = true;
}
if (txt % 10 == 0) {
document.body.background = '';
}
document.getElementById("timer").innerHTML = txt;
}
</script>
</head>
<body background="yamiwall.jpeg" bgcolor="black" onload="initialize()">
<div align="center">
<input type="button" onclick="start()" value="start">
<input type="button" onclick="stop()" value="stop">
<input type="button" onclick="reset()" value="reset">
</div>
<div align="center">
<span id="timer" style="color:white;font-size:360pt;">120</span>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment