Newer
Older
2022-S.Shinya / docs / kuji.js
function CountDown() {
    var count = 4,
    tmID,
    infobox = document.getElementById("start"),
    hit = document.getElementById("true"),
    finish = document.getElementById("info");
    function CountDown() {
        if (--count < 1) {
            finish.innerHTML = "終了";
            hit.removeEventListener("click", stopCountDown, false);

        } else {
            finish.innerHTML = "残り" + count + "秒";
            tmID = setTimeout(CountDown, 1000);
        }
    }
    function startCountDown() {
        tmID = setTimeout(CountDown, 1000);
        infobox.removeEventListener("click", startCountDown, false);
        hit.addEventListener("click", stopCountDown, false);
    }
    function stopCountDown() {
        if (count >= 0) {
            clearTimeout(tmID);
            finish.innerHTML = "あたりを引きました!"
        }

	hit.innerHTML = "[HIT!]";
	hit.removeEventListener("click", stopCountDown, false);
    }
    infobox.addEventListener("click", startCountDown, false);  
}
document.addEventListener("DOMContentLoaded", CountDown, false);