This article shares the specific code of JavaScript to achieve the front-end countdown effect for your reference. The specific content is as follows Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> div { padding: 10px; font-size: 100px; } p { float: left; width: 300px; height: 300px; border: 1px solid #000000; color: #ffffff; background-color: #333333; text-align: center; line-height: 300px; } </style> </head> <body> <div> <p class="hour">1</p> <p class="minute">2</p> <p class="second">3</p> </div> <script> window.addEventListener('load', function() { //Get elementsvar hour = document.querySelector('.hour'); //Black box for hoursvar minute = document.querySelector('.minute'); //Black box for minutesvar second = document.querySelector('.second'); //Black box for secondsvar inputTime = +new Date('2021-2-6 18:00:00'); //Returns the total number of milliseconds of the user input timecountDown(); //Call this function once to prevent the page from being blank when it is refreshed for the first time//Start the timersetInterval(countDown, 1000); function countDown() { var nowTime = +new Date(); //Returns the total number of milliseconds of the current time var times = (inputTime - nowTime) / 1000; //tiems is the total number of milliseconds of the remaining time var h = parseInt(times / 60 / 60 % 24); //h = h < 10 ? '0' + h : h; hour.innerHTML = h; //Give the remaining hours to the hour black box var m = parseInt(times / 60 % 60); //minutes m = m < 10 ? '0' + m : m; minute.innerHTML = m; var s = parseInt(times % 60); //Current seconds s = s < 10 ? '0' + s : s; second.innerHTML = s; } }) </script> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: View the frequently used SQL statements in MySQL (detailed explanation)
Introduction to structure and performance HTML st...
The final effect is as follows: The animation is ...
Table of contents Preface 1. Recursive components...
Table of contents 1. Pull the centos image 2. Bui...
1. Install MySQL database ① Download and unzip an...
A common suggestion is to create indexes for WHER...
When we use the like % wildcard, we often encount...
Table of contents Written in front Login Overview...
Table of contents 1. Background 2. Understanding ...
Drag the mouse to take a screenshot of the page (...
Linux and Unix are multi-user operating systems, ...
Scenario: After installing the latest version of ...
1. Linux kernel driver module mechanism Static lo...
1. flex-direction: (direction of element arrangem...
First look at the effect: When the mouse moves ov...