본문 바로가기

오늘의 비글링/따라잡기

Count Down (카운트다운)

세상 간단한 카운트 다운 구현


<html>


<span id="days"></span>

<span id="hours"></span>

<span id="minutes"></span>

<span id="seconds"></span>




<js>


const second = 1000,

minute = second * 60,

hour = minute * 60,

day = hour * 24;


let countDown = new Date('Sep 30, 2018 00:00:00').getTime(),

x = setInterval(function() {


let now = new Date().getTime(),

    distance = countDown - now;


document.getElementById('days').innerHTML = Math.floor(distance / (day)),

  document.getElementById('hours').innerHTML = Math.floor((distance % (day)) / (hour)),

  document.getElementById('minutes').innerHTML = Math.floor((distance % (hour)) / (minute)),

  document.getElementById('seconds').innerHTML = Math.floor((distance % (minute)) / second);


//do something later when date is reached

//if (distance < 0) {

//  clearInterval(x);

//  'IT'S MY BIRTHDAY!;

//}


}, second)



하이라이트 한 부분만 맞춰주면 끝~!

'오늘의 비글링 > 따라잡기' 카테고리의 다른 글

Webpack 완전정복하기!!  (0) 2019.07.31
Webpack의 혼란스런 사항들  (0) 2019.07.31
.sh 실행파일 만들기  (0) 2018.11.07
랜덤스트링생성(JS)  (0) 2018.02.20
프로그레스바 (Progress Bar)  (0) 2018.02.17