This article mainly shares the sample code for implementing the holiday time countdown function in native js. Friends who are interested can come and see it together.
Knowledge points
1. Implementation principle:
Use end time - current time = Time difference
The time difference will naturally decrease by 1 second every time the current time passes.
So the current time needs to be updated once every second to achieve the countdown effect
2. What needs to be paid attention to is the conversion between times and the processing of the obtained values
3. Methods used:
obj.getTime() //换算成毫秒 Math.floor() //把小数点向下舍入结果取一个整数 50%24 // 这是对数值求余的方法,意思是 假如有50个小时,一天24个小时 这个得出的结果就是 余数是2
There are detailed comments in the complete code for specific numerical calculation processing
Complete code
Note: The code comes with a code that displays the current time. The standard format and countdown days
are what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Detailed explanation of the use of event delegation in JS
Yuansheng JS creates a lottery page
p5.jsRealizing Golden Spiral Animation
The above is the detailed content of Native js implements holiday time countdown function (code attached). For more information, please follow other related articles on the PHP Chinese website!