注册
登录

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="container">
<h2><span>距离新年</span>2025</h2>
<div class="countdown">
<div id="day"> </div>
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
</div>
</div>
<script>
const countDate = new Date('Jan 1,2025 00:00:00').getTime();
function newYear(){
const now = new Date().getTime();
const gap = countDate - now;
console.log('gap:'+gap);
const seacond = 1000;
const minute = seacond * 60;
const hour = minute * 60;
const day = hour * 24;
const d= Math.floor(gap/(day))
const h= Math.floor((gap % (day))/(hour))
const m= Math.floor((gap % (hour))/(minute))
const w= Math.floor((gap % (minute))/(seacond))
document.getElementById('day').innerText=d
document.getElementById('hour').innerText=h
document.getElementById('minute').innerText=m
document.getElementById('second').innerText=w
}
setInterval(function(){
newYear();
},1000)
</script>
</body>
</html>
style.css
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
background-image: url(bg2.jpeg) ;
background-repeat: no-repeat;
background-size: cover;
background-blend-mode: hard-light;
}
.container {
position: absolute;
top: 80px;
left: 100px;
right: 100px;
bottom: 100px;
display: flex;
justify-content: center;
align-items: center;
background-image: url(bg2.jpeg);
background-size: cover;
background-attachment: fixed;
flex-direction: column;
box-shadow: 0 50px 50px rgba(0, 0, 0, 0.5),
0 0 0 100px rgba(0, 0, 0, .1);
}
.container h2{
text-align: center;
font-size: 10em;
line-height: 0.7em;
color: #333;
margin-top: -80px;
}
.container h2 span {
display: block;
font-weight: 300;
letter-spacing: 6px;
font-size: 0.2em;
}
.countdown{
display: flex;
margin-top: 50px;
}
.countdown div{
position: relative;
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
background-color: #333;
color: #fff;
margin: 0 15px;
font-size: 3em;
font-weight: 500;
}
.countdown div:before{
content: '';
position:absolute;
left: 0;
bottom: -30px;
width: 100%;
height: 35px;
background-color: #ff0;
color: #333;
font-size: 0.35em;
line-height: 35px;
font-weight: 300;
}
.countdown div#day:before{
content: "天";
}
.countdown div#hour:before{
content: "小时";
}
.countdown div#minute:before{
content: "分钟";
}
.countdown div#second:before{
content: "秒";
}
背景图
