Skip to content

Instantly share code, notes, and snippets.

@kits
Created March 19, 2020 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kits/1b2986339dbce49d4c05686c555745a2 to your computer and use it in GitHub Desktop.
Save kits/1b2986339dbce49d4c05686c555745a2 to your computer and use it in GitHub Desktop.
stopwatch.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<style>
input {
font-size: 64px;
width: 310px;
font-family: Courier, monospace;
border: none;
}
button {
font-size: 24px;
width: 310px;
font-family: "Times New Roman", serif;
}
</style>
<title>stopwatch</title>
</head>
<body>
<form name="f">
<input name="t" type="text" value=""><br>
<button name="b" type="button" onclick="onoff()">start/stop</button>
</form>
<script>
var t = document.f.t;
t.value = "--:--:--";
var st, tid;
function onoff() {
if (st) {
clearTimeout(tid);
st = null;
return;
}
st = (new Date).getTime();
sw();
}
function sw() {
var now = (new Date).getTime();
var ela = new Date(now - st);
t.value = ela.toISOString().substring(11, 19);
tid = setTimeout(sw, 100);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment