html, CSS, JS wrote a 2021 countdown

Countdown effect is shown:

The main layout with five div, main js code as follows:

<script type="text/javascript">
        var s1="2021-1-1,0:0:0";
        window.onload=function(){
            date();
            function zero(i){
                return i<10?"0"+i:i+"";
            }
            function date(){
                var d=document.getElementById("day");
                var h=document.getElementById("hour");
                var m=document.getElementById("minute");
                var s=document.getElementById("second");
                nowtime =wasnew Date();
                //var endtime=new Date("2020/1/5,00:00:00");//2020-1-1,0:0:0
                var endtime=new Date(s1);
                var time=parseInt((endtime.getTime()-nowtime.getTime())/1000);
                var day=parseInt(time/(24*60*60));
                var hour=parseInt(time/(60*60)%24);
                var minute=parseInt(time/60%60);
                var second=parseInt(time%60);
                day=zero(day);
                hour=zero(hour);
                minute=zero(minute);
                second=zero(second);//+零    
                d.innerHTML=day;
                h.innerHTML=hour;
                m.innerHTML=minute;
                s.innerHTML=second;
                setTimeout(date,1000);
            }
    }
    </script>

The latter can be added to achieve enter a time. Time to look at how long distance input.

Guess you like

Origin www.cnblogs.com/Tisou1/p/12158645.html