<!DOCTYPE html>
<html lang="en">
<script src="jquery-1.8.2.min.js"></script>
<script src="jq.snow.js"></script>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.cutdowntime {
width: 578px;
margin: 300px auto 0;
}
.cutdowntime strong {
display: block;
font-size: 30px;
color: #fff;
margin-bottom: 20px;
}
.cutdowntime span {
display: inline-block;
margin: 0 0 0 3px;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
background-color: #000;
font-size: 40px;
color: #fff;
}
.cutdowntime span:nth-child(2n+1) {
width: 30px;
text-align: center;
font-size: 20px;
background: none;
vertical-align: top;
}
</style>
</head>
<body style="background-color:crimson; overflow: hidden;">
<div class="cutdowntime">
<strong>距离2020年春节还有:</strong>
<span class="dates">00</span>
<span>天</span>
<span class="hour">00</span>
<span>时</span>
<span class="minute">00</span>
<span>分</span>
<span class="second">00</span>
<span>秒</span>
</div>
<script>
//1、获取元素
window.addEventListener('load', function() {
var bodyHeight = document.documentElement.clientHeight;
// console.log(bodyHeight);
document.body.style.height = bodyHeight + 'px'
})
var dates = document.querySelector('.dates');
var hour = document.querySelector('.hour');
var minute = document.querySelector('.minute');
var second = document.querySelector('.second');
var iptTime = +new Date('2020-01-24 00:00:00');
countDown();
setInterval(countDown, 1000);
$(function() {
$.fn.snow({
minSize: 5, //雪花的最小尺寸
maxSize: 40, //雪花的最大尺寸
newOn: 100 //雪花出现的频率 这个数值越小雪花越多
});
});
function countDown() {
var nowsTime = +new Date();
var time = (iptTime - nowsTime) / 1000; //剩余时间总的描述
var d = parseInt(time / 60 / 60 / 24); //天
var d = d < 10 ? '0' + d : d;
dates.innerHTML = d;
var h = parseInt(time / 60 / 60 % 24); //时
var h = h < 10 ? '0' + h : h;
hour.innerHTML = h;
var m = parseInt(time / 60 % 60); //分
var m = m < 10 ? '0' + m : m;
minute.innerHTML = m;
var s = parseInt(time % 60); //秒
var s = s < 10 ? '0' + s : s;
second.innerHTML = s;
//return '距离' + times + ' 还有' + d + '天' + h + '时' + m + '分' + s + '秒';
}
//console.log(countDown('2020-01-24 00:00:00'));
</script>
</body>
</html>
雪花效果:https://blog.csdn.net/ghjzzhg/article/details/86088481