This article example shares the specific code of JavaScript to achieve the digital clock effect for your reference. The specific content is as follows RenderingDemand Analysis 1. Get time through date source codeHTML Part <div id="div"> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> seconds</div> CSS part <style> /*none*/ </style> JavaScript <script> // Requirement: digital clock var date = new Date(); var imgArr = document.getElementsByTagName('img'); //Get a collection of img pictures var hours, minutes, seconds; var time = setInterval(function () { date = new Date(); // Get hours hours = date.getHours(); imgArr[0].src = "img/" + parseInt(hours / 10) + ".png" imgArr[1].src = "img/" + hours % 10 + ".png" // Get minutes minutes = date.getMinutes(); imgArr[2].src = "img/" + parseInt(minutes / 10) + ".png" imgArr[3].src = "img/" + minutes % 10 + ".png" // Get seconds seconds = date.getSeconds(); imgArr[4].src = "img/" + parseInt(seconds / 10) + ".png" imgArr[5].src = "img/" + seconds % 10 + ".png" console.log(hours); console.log(minutes); console.log(seconds); }, 1000) </script> Total code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="div"> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> <img src="img/0.png" /> seconds</div> </body> </html> <script> // Requirement: digital clock var date = new Date(); var imgArr = document.getElementsByTagName('img'); //Get a collection of img pictures var hours, minutes, seconds; var time = setInterval(function () { date = new Date(); // Get hours hours = date.getHours(); imgArr[0].src = "img/" + parseInt(hours / 10) + ".png" imgArr[1].src = "img/" + hours % 10 + ".png" // Get minutes minutes = date.getMinutes(); imgArr[2].src = "img/" + parseInt(minutes / 10) + ".png" imgArr[3].src = "img/" + minutes % 10 + ".png" // Get seconds seconds = date.getSeconds(); imgArr[4].src = "img/" + parseInt(seconds / 10) + ".png" imgArr[5].src = "img/" + seconds % 10 + ".png" }, 1000) </script> Images used: Since you don't have pictures, directly copying the code will not show the effect. You can find a few pictures to replace them and modify them slightly. As long as you can understand the code, there will be no problem in modifying it. 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:
|
<<: Detailed explanation of CentOS configuration of Nginx official Yum source
>>: 4 Ways to Quickly Teach Yourself Linux Commands
Preface An index is a data structure that sorts o...
Table of contents 1. Introduction Second practice...
Background Recently, I encountered such a problem...
Check the transaction isolation level In MySQL, y...
Preface Recently, I encountered a requirement at ...
When we use TypeScript, we want to use the type s...
Preface Using Docker and VS Code can optimize the...
This time we use HTML+CSS layout to make a prelim...
Detailed explanation of creating MySql scheduled ...
Problem Description 1. Database of the collection...
1. How MySQL uses indexes Indexes are used to qui...
The execution relationship between the href jump ...
first step Delete it once with the built-in packa...
1 Effect Demo address: https://www.albertyy.com/2...
Because the data binding mechanism of Vue and oth...