How To Create New Year Countdown 2023 Using Javascript

How To Create New Year Countdown 2023 Using Javascript

 

Welcome to the CodeWithRandom blog. In this blog, we learn how to create a New Year Countdown Project. We use HTML, Css &  javascript for this New Year Countdown Project.

Hope you enjoy our blog so let’s start with a basic HTML structure for a New Year Countdown.

HTML Code For New Year Countdown

<div class="wrapper">
<div class="container text-center">
<div class="col-md-12">
<h1 id="header" class="">New Year Countdown</h1>
</div>
<div class="col-md-3 col-xs-6">
<div class="clock">
<div class="well top-pane">
<div id="days" class="num">00</div>
</div>
<div class="well bottom-pane">
<div id="days-text" class="text">Days</div>
</div>
</div>
</div>
<div class="col-md-3 col-xs-6">
<div class="clock">
<div class="well top-pane">
<div id="hours" class="num">00</div>
</div>
<div class="well bottom-pane">
<div id="hours-text" class="text">Hours</div>
</div>
</div>
</div>
<div class="col-md-3 col-xs-6">
<div class="clock">
<div class="well top-pane">
<div id="mins" class="num">00</div>
</div>
<div class="well bottom-pane">
<div id="mins-text" class="text">Minutes</div>
</div>
</div>
</div>
<div class="col-md-3 col-xs-6">
<div class="clock">
<div class="well top-pane">
<div id="secs" class="num">00</div>
</div>
<div class="well bottom-pane">
<div id="secs-text" class="text">Seconds</div>
</div>
</div>
</div>
<div id="info" class="small"></div>
</div>
</div>

There is all HTML code for the New Year Countdown. Now, you can see output without CSS, then we write javascript for the New Year Countdown.

Portfolio Website Using HTML ,CSS and Javascript Source Code

 

output

 

 

CSS Code For New Year Countdown

html {
height: 100%;
background: radial-gradient(ellipse at bottom, #1B2735 0%, #090A0F 100%);
overflow: hidden;
}
body {
background: transparent;
color: #ffffff;
}
.bluelight {
text-shadow: 0 0 10px #3498DB,
0 0 20px #3498DB,
0 0 30px #3498DB,
0 0 40px #2980B9,
0 0 70px #2980B9,
0 0 80px #2980B9,
0 0 100px #2980B9,
0 0 150px #2980B9;
}
.clock {
overflow: hidden;
}
.col-md-12 {
overflow: hidden;
padding-bottom: 20px;
}
.top-pane {
margin-bottom: 0px;
border-radius: 5px 5px 0px 0px;
background-color: #34495E;
border: 0px;
}
.bottom-pane {
margin-top: 0px;
border-radius: 0px 0px 5px 5px;
background-color: #2C3E50;
border: 0px;
}
@media (min-width: 768px) {
.num {
font-size: 100px;
}
}
@media (max-width: 767px) {
.num {
font-size: 50px;
}
}
@media (max-width: 480px) {
.num {
font-size: 30px;
}
}
@media (min-width: 768px) {
.text {
font-size: 35px;
}
}
@media (max-width: 767px) {
.text {
font-size: 20px;
}
}
@media (max-width: 480px) {
.text {
font-size: 15px;
}
}
@media (min-width: 768px) {
body {
padding-top: 75px;
}
}
h1 {
padding-top: 10px;
}
@media (min-width: 768px) {
h1 {
margin-bottom: 75px;
font-size: 100px;
}
}

Now we have completed our CSS section,  Here is our updated output CSS.
output

 

Now add javascript for functionality.

Javascript code For New Year Countdown

function timeLeft(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
};
$(document).ready(function() {
var today = new Date();
var deadline = 'January 1 ' + (today.getFullYear() + 1) + " 00:00:00";
if (today.getMonth() == 0 && today.getDate() == 1) {
deadline = 'January 1 ' + (today.getFullYear()) + " 00:00:00";
};
$("#header").hover(function() {
$(this).toggleClass('bluelight');
});
$(".clock").hover(function() {
$(this).toggleClass('bluelight');
});
var setClock = function(newyear){
var timeinterval = setInterval(function(){
var t = timeLeft(newyear);
$('#days').text(t.days);
$('#hours').text(t.hours);
$('#mins').text(('0' + t.minutes).slice(-2));
$('#secs').text(('0' + t.seconds).slice(-2));
if(t.total<=0){
clearInterval(timeinterval);
var now = new Date();
var yearStr = now.getFullYear().toString();
$('#header').text("Happy New Year!!!");
$('#days').text(yearStr[0]);
$('#days-text').text("Happy");
$('#hours').text(yearStr[1]);
$('#hours-text').text("New");
$('#mins').text(yearStr[2]);
$('#mins-text').text("Year");
$('#secs').text(yearStr[3]);
$('#secs-text').text("!!!");
$('#info').text("Countdown starts again tomorrow!");
}
},1000);
};
setClock(deadline);
});

Final output For New Year Countdown

 

 

Now we have completed our javascript section,  Here is our updated output with javascript. Hope you like the New Year Countdown. you can see output video and project screenshots. See our other blogs and gain knowledge in front-end development.

100+ Front-end Projects for Web developers (Source Code)

Thank you

In this post, we learn how to create an New Year Countdown using simple HTML & CSS and javascript. If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.

Written by – Code With Random/Anki

Leave a Reply