HTML部分:
CSS部分:
*{ margin: 0; padding: 0;} .div{ width:100%;height:636px;background: linear-gradient(to top, #333 0%, #fff 100%);} #div{ box-sizing: border-box;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-100%);font-family: STXingkai;font-size: 50PX;}
JS部分:
function biao2(){ var div = document.getElementById("div"); var dt = new Date("2018-1-12 12:00:00") - new Date(); //假设倒计时时间为明天十二点开始减去今天的时间, 算出明天距离今天所剩的毫秒数 if(dt>0){ hours=Math.floor(dt/1000/60/60%24); min=Math.floor(dt/1000/60%60); sec=Math.floor(dt/1000%60); } div.innerHTML="倒计时:"+hours+"时"+min+"分"+sec+"秒"; } setInterval("biao2()",1000);