Skip to content

Instantly share code, notes, and snippets.

@kroteDev
Created September 20, 2020 14:07
Show Gist options
  • Save kroteDev/6cb624279f3a7141b18ab5dc81ce7899 to your computer and use it in GitHub Desktop.
Save kroteDev/6cb624279f3a7141b18ab5dc81ce7899 to your computer and use it in GitHub Desktop.
CountDown App
<div class="overlay"></div>
<div class="countdown-container">
<header>
<h1>Until new beginnings</h1>
</header>
<div class="countdown">
<div class="elements" id="months">
<h2></h2>
<span>Months</span>
</div>
<div class="elements" id="days">
<h2></h2>
<span>Days</span>
</div><div class="elements" id="hours">
<h2></h2>
<span>Hours</span>
</div><div class="elements" id="minutes">
<h2></h2>
<span>Minutes</span>
</div><div class="elements" id="seconds">
<h2></h2>
<span>Seconds</span>
</div>
</div>
<div id="infolog"></div>
</div>
//Div created To log
const log = document.getElementById("infolog");
//Get All The elements
const monthsContainer = document.querySelector('#months h2');
const daysContainer = document.querySelector('#days h2');
const hoursContainer = document.querySelector('#hours h2');
const minutesContainer = document.querySelector('#minutes h2');
const secondsContainer = document.querySelector('#seconds h2');
function countDown(){
//Get The Current timeDate
const currentDate = new Date();
//The End date of the CountDown
const endDate = new Date('10/04/2020');
//Get the total resting time in miliseconds
const miliSeconds = (endDate - currentDate);
//one second has one thousand miliseconds.
const totalSeconds = miliSeconds / 1000 ;
//formated Seconds
const seconds = Math.floor(totalSeconds) %60 ;
//one minute has sixty seconds. total Minutes
const totalMinutes = Math.floor(totalSeconds / 60);
//minutes of current hour.
const minutes = Math.floor(totalSeconds / 60) % 60;
//One Hour has 60 minutes or 3600 seconds
const totalHours = Math.floor(totalSeconds /3600 );
//Formated hours of the current day
const hours = Math.floor(totalSeconds / 3600) % 24;
//One day has 24 hours and each hour has 3600 seconds second option const days2 = Math.floor(totalSeconds / (3600*24) );
const days = Math.floor(totalSeconds / 3600 / 24);
//Each monht has roughly 30 days.So i divided the amout of days for 30 to get the months
const months = Math.floor(days / 30);
//Update UI
monthsContainer.innerHTML = months;
daysContainer.innerHTML = days;
hoursContainer.innerHTML = formatTime(hours);
minutesContainer.innerHTML = formatTime(minutes);
secondsContainer.innerHTML = formatTime(seconds);
}
function formatTime(time){
return time < 10 ? `0${time}` : time;
}
setInterval(countDown, 1000);
@import url('https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@300;400;700');
body, html{
margin: 0px;
padding: 0px;
box-sizing: border-box;
font-family: 'Roboto Slab', serif;
font-weight: 400;
}
body{
z-index:0;
min-height: 100vh;
background: rgba(0,0,0, 0.5) url('https://images.unsplash.com/photo-1490813373953-6477c0b5b90a?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ') no-repeat center top;
background-size: cover;
}
.overlay{
position:absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background- color:rgba(10,10,10,0.6);
z-index: 1;
}
.countdown-container{
position: relative;
z-index: 2;
width:800px;
margin: 10% auto 0px;
color: #ffffff;
}
.countdown-container h1{
width: 100%;
margin-bottom: 30px;
font-size: 2rem;
margin-top:0px;
font-weight: 400;
}
.countdown-container .countdown{
display: flex;
}
.countdown-container .elements{
width: 20%;
text-align: center;
font-weight: 300;
}
.countdown-container .elements h2{
font-size:5rem;
line-height: 1;
margin:0px;
font-weight: 700;
margin-bottom: 10px;
}
/* Custom div to log while developing*/
#infolog{
display: none;
background-color: #fff;
color: #666;
margin:50px auto;
width:600px;
height: 200px;
border-radius:7px;
scroll-y:visible;
padding: 20px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment