Let's take a look at two pictures to see what we want to write today:
See what is in the upper-right corner of the image? See what is in the image below?
I believe that everyone will not be unfamiliar with this. Those who live in the middle of the seckilling, waiting to rob Xiaomi people, anxiously waiting for you to stare at it for a second, I don't know the answer, but I know that a group of people may have started to count in one second. The annual college entrance examination is coming again, and the countdown time is getting smaller and smaller. I don't know which ones are counting the exam time and which ones are counting the graduation time, which of the following are the pure times of relief.
Let's get down to the truth and write down the countdown today. It's actually quite simple now, but let's analyze it by steps:
Effect:
The time is reduced by "seconds" to achieve dynamic reduction.
Implementation principle:
First, we can determine the countdown duration, that is, the maximum value, and then describe the maximum value in days, hours, minutes, or seconds to dynamically decrease the maximum countdown duration per second, dynamic results show that the current maximum duration is displayed at any time, and the loop ends after the countdown ends, and the decline is stopped.
Here it takes a few seconds to convert: 1 second (s) = 1000 milliseconds (MS), as for the conversion between days, hours, minutes, seconds Needless to say
Note: The specified period of scheduled call for setinterval is millisecond (MS)
Code implementation:
The Code is as follows:
Window. onload = function showDate () {var needTime = 60; var dateTime = function () {var hour = Math. floor (needTime/(3600*60); var minute = Math. floor (needTime/60) % 60); // minute conversion, // 60 describes the remaining parts divided by hours, % 60 indicates that the remaining part after the division cannot be divisible by seconds is divided into var second = Math. floor (needTime % 60); // The number of hour seconds that cannot be divisible by seconds <0? Hour = 0: hour = hour; // This conditional operator is refreshing. It has never been used several times since I learned it. I feel a lot more concise when I use it. <0? Minute = 0: minute = minute; second <0? Second = 0: second = second; hour. toString (). length <2? Hstr = "0" + hour. toString (): hstr = hour; // 1 shows 01minute. toString (). length <2? Mstr = "0" + minute. toString (): mstr = minute; // 1 shows 01second. toString (). length <2? Sstr = "0" + second. toString (): sstr = second; // 1 display 01 timestr = hstr + ":" + mstr + ":" + sstr; needTime = needTime-1; // needTime -- either; if (needTime = 0) {clearInterval (dateTime);} document. getElementById ("ce "). innerHTML = timestr;}; window. setInterval (dateTime, 1000); // call method. If it is defined, you can directly call the specified name without adding ()}; </script>
The html part is simpler. You can write a div property id = "ce". Of course, if you want a style, you can write it separately. It is actually a timer application, I still remember that I was just in touch with this industry. I was working on a book website and wanted to get a countdown auction. I found some information. After reading it for a long time, I still felt too much trouble. The result... in this case, the stopwatch is useless. In the same principle, it's a reduction and an increase.
As long as we keep moving, we will keep improving. Well, I can only comfort myself so much...