カウントダウンJSを書いてみた

久しぶりの更新です。特に何もないのですが、NIKEのレアスニーカーで偽物に翻弄されながらも投資してます。stockxのポートフォリオがちゃんと動かなくて辛い。

さて、表題の通り、動的にカウントダウン表示するJSをjQueryを使って即興で書いてみた。アレコレご意見頂けると元喜び組!

<script
  src="https://code.jquery.com/jquery-3.5.1.js"
  integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
  crossorigin="anonymous"></script>
<script>

// init
var count_sec = 10;
showCount(count_sec);
var redirecturl = $("#redirecturl").text();
//console.log("redirectURL", redirecturl);

//
$(function(){
	// カウントダウン表示
	setInterval(function(){
		//
		count_sec--;
		if (count_sec >= 0) {
			showCount(count_sec);

		} else {
			if (redirecturl) {
				window.location = redirecturl;
			}
		}
	},1000);
});

function showCount(count_sec) {
	var obj = $(".countdown");
	obj.html(count_sec);
	return;
}

</script>
© takashick.tk 2023.