当前位置:网站首页>Page countdown
Page countdown
2022-07-05 05:02:00 【Fierce chicken】
Make a simple web page countdown timer . This countdown can be counted down according to the entered deadline , The entered deadline data will be cached locally (“deadlineDate”)( See the end of the article for the source code )
Native is used here JS Write relevant web page logic , Mainly applied to API Yes
document.getElementById()
: Used to get DOM Element nodes , It is convenient to fill in data to the node and displayWindow.setInterval()
: Used to refresh the displayed countdown data every second . This is the key to realize this countdown functionelem.addEventListener()
: For binding events , Here is only the click event used to bind the reset button- Built-in objects
Date
: Used to get all time-related values
The whole web application is divided into two main parts : Countdown display part and countdown setting part
When you enter this page , If the deadline is not set , Then the default deadline is the time of entering the page , The countdown display part does not run . You need to input the date and time in the specified format according to the prompt in the input box , Can make the countdown run . but Here I don't have fault tolerance for date input , Unable to process user's wrong input
The maximum unit of countdown display is “ God ”, When the remaining time is less than 1 days , This unit will not appear
New content recognized in the coding process
In the face of Date Object to perform basic operations ( Except addition , This is string splicing , call toString()
) when Date Object will automatically call valueOf()
The number of milliseconds converted to integer
Date Object instances can change time directly by subtraction , Now with Date The integer that the object subtracts represents the number of milliseconds
such as :let deadlineDate = new Date(); console.log(deadlineDate); // The output is the date string deadlineDate -= 24 * 60 * 60 * 1000; // At this time, the date is reduced by one day console.log(deadlineDate); // The output is the number of milliseconds
In fact, you can also multiply 、 Operations such as division change the value , You can also use comparison operators to directly compare time ( This is the comparison of milliseconds ), The date object will automatically call
valueOf()
Convert to millisecond value . Except addition , Because at this time, it becomes string splicinglet deadlineDate = new Date(); console.log(deadlineDate + 24 * 60 * 60 * 1000); // Concatenation of date string and numeric value console.log(deadlineDate * 2); // Twice the original millisecond value
Date Object instances can be directly associated with Date Object instances are subtracted , It can also be directly related to the number of milliseconds ( Integers ) Subtracting the , At this time, it represents the subtraction of two milliseconds
such as :let deadlineDate = new Date("2021-6-26 17:00:00"); let deadlineMillis = +new Date(); let curTime = new Date(); console.log(deadlineDate - curTime); // At this time, the difference between the output milliseconds console.log(deadlineMillis - curTime); // At this time, the difference between the output milliseconds
In fact, it can also be other basic operations besides addition , Here, date objects are automatically converted into milliseconds for operation
Article source :https://gitee.com/thisismyaddress/bocheng-blogs/tree/master/ Web page effects / Web countdown
边栏推荐
- Create a pyGame window with a blue background
- Understand encodefloatrgba and decodefloatrgba
- Autocad-- dynamic zoom
- How much do you know about 3DMAX rendering skills and HDRI light sources? Dry goods sharing
- 中国AS树脂市场调研与投资预测报告(2022版)
- 2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
- 3dsmax snaps to frozen objects
- BUUCTF MISC
- 2022 / 7 / 1 Résumé de l'étude
- 嵌入式数据库开发编程(六)——C API
猜你喜欢
AutoCAD - Document Management
669. Prune binary search tree ●●
2021 higher education social cup mathematical modeling national tournament ABCD questions - problem solving ideas - Mathematical Modeling
Unity check whether the two objects have obstacles by ray
How to choose a panoramic camera that suits you?
Thinking of 2022 American College Students' mathematical modeling competition
LeetCode之单词搜索(回溯法求解)
669. 修剪二叉搜索树 ●●
3dsmax snaps to frozen objects
54. 螺旋矩阵 & 59. 螺旋矩阵 II ●●
随机推荐
Sqlserver stored procedures pass array parameters
How to choose a panoramic camera that suits you?
2022/7/2做题总结
2022 thinking of mathematical modeling C problem of American college students / analysis of 2022 American competition C problem
2022 U.S. college students' mathematical modeling e problem ideas / 2022 U.S. game e problem analysis
2020-10-27
Unity intelligent NPC production -- pre judgment walking (method 1)
Data is stored in the form of table
Basic knowledge points
GameObject class and transform class of unity
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
嵌入式数据库开发编程(六)——C API
Cocos progress bar progresstimer
Rip notes [rip three timers, the role of horizontal segmentation, rip automatic summary, and the role of network]
《动手学深度学习》学习笔记
Detailed explanation of the ranking of the best universities
UE4/UE5 虚幻引擎,材质篇(三),不同距离的材质优化
Listview pull-down loading function
Pdf to DWG in CAD
Django reports an error when connecting to the database. What is the reason