Part I wrote about the effect of the realization of the countdown, countdown now share a simple case, not much to say directly on the code
HTML part:
<div id="box"> <h1>倒计时</h1> <div class="container"> <span class="hour">1</span> <span class="minute">2</span> <span class="second">3</span> </div> </div>
css section:
#box{ width: 300px; height: 300px; margin: 200px auto; text-align: center; background: red; } .container{ height: 200px; /*margin: 200px auto;*/ display: flex; flex-direction: row; align-items: center; } .container span{ vertical-align: middle; background-color: #000000; color: #FFFFFF; flex-grow: 1; font-size: 28px; height: 50px; line-height: 50px; text-align: center; margin: 0px 10px; }
js part:
<Script>
var hour = document.querySelector ( 'hour.' );
var minute document.querySelector = ( 'minute.' ); var SECOND document.querySelector = ( 'SECOND.' ); var inputTime + = new new a Date ( ' 2019-8-16 24:00:00 '); // returns the user to enter the total time of a few milliseconds conutDown (); // first call the function to prevent the first time to refresh the page blank // starts a timer setInterval (conutDown, 1000 ); function conutDown () { var nowtime + = new new a Date (); // returns the current time the total number of milliseconds //times the total number of seconds remaining time var times = (inputTime - nowtime) / 1000 ; var H = the parseInt (times / 60/60 24%); when // H = H <10 '0' +? H: H; // ternary expressions with, if h is less than 10, to add a variable h 0 before hour.innerHTML = h; var m = the parseInt (Times / 60% 60); // points m = m <10 '0' +? m: m; minute.innerHTML = m; var S = the parseInt (Times 60%); // second S = S <10 '0' +? S: S; second.innerHTML = S; }
</ Script>
May be a bit sketchy, please bear with me