英語のSPRINTしようと思ったら学校のパソコンにタイマーの機能ってないなーと思ってサイトに追加してたらSPRINTができてなかった
ヘッダーや、天気予報の時計の横から使用できます。
スマホでどうなってるかは知りません。
コード(ほぼコピペ)
<body style="background:transparent;">
<section class="passsec text-center container">
<p>
<div id="showArea" class="showRaceTime"></div>
</p>
<br>
<p>
<ul id="showLapArea" class="showLap">
</ul>
</p>
</section>
</body>
<script>
//keydown code
document.onkeydown = keydown;
let flag = 0; //flag 0 -> not running, 1 -> running
function keydown(){
if(event.key == "Enter" && flag == 0){
start();
}
else if(event.key == "Enter" && flag == 1){
stop();
}
else if(event.key == "r"){
reset();
}
else if(event.key == "l" && flag == 1){
lap();
}
}
//keydown end
//addzero code
function addzero(num){
if(num < 10){
ret = "0" + num;
return ret;
} else {
return num;
}
}
//addzero end
//passsec code
var passSec,passMsec,passMin,lapnum;
passMsec = 0;
passSec = 0;
passMin = 0;
lapnum = 0;
var defaultmsg = "00:00:00";
var defaultlap = "LAP0" + " " + "/" + " " + "00:00:00"
document.getElementById("showArea").innerHTML = defaultmsg;
function showSec(){
passMsec++;
if(passMsec > 99){
passMsec = 0;
passSec++;
}
if(passSec > 59){
passSec = 0;
passMin++;
}
var msg = addzero(passMin) + ":" + addzero(passSec) + ":" + addzero(passMsec);
document.getElementById("showArea").innerHTML = msg;
}
function start(){
timer = setInterval('showSec()',10);
flag = 1;
}
function stop(){
clearInterval(timer);
flag = 0;
}
function reset(){
passSec = 0;
passMsec = 0;
passMin = 0;
lapnum = 0;
var resetlap = "LAP" + lapnum + " " + "/" + " " + addzero(passMin) + ":" + addzero(passSec) + ":" + addzero(passMsec);
clearInterval(timer);
document.getElementById("showArea").innerHTML = defaultmsg;
document.getElementById("showLapArea").innerHTML = "";
flag = 0;
}
function lap(){
lapnum++;
var laptime = "LAP" + lapnum + " " + "/" + " " + addzero(passMin) + ":" + addzero(passSec) + ":" + addzero(passMsec);
var lapArea = document.getElementById("showLapArea");
var makeli = document.createElement("li");
makeli.innerHTML = laptime;
lapArea.appendChild(makeli);
}
//passsec end
</script>
<style>
li{
list-style: none;
}
.passsec{
text-align: center;
font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif;
}
.showRaceTime{
text-align: center;
font-size: 90px;
color: #ffffff;
font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif;
}
.showLap{
text-align: center;
font-size: 20px;
color: #2EA2FF;
font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif;
</s}tyle>