js流动式效果显示当前系统时间

js流动式效果显示当前系统时间

实现代码:

<!DOCTYPE html> <html> <head> <title>js流动时间</title> <style type="text/css"> #divH, #divM, #divS { font-family: consal; line-height: 30px; position: absolute; left: 0px; width: 5760px; color: white; } #divH { background-color: #606; } #divM { background-color: #060; } #divS { background-color: #006; } #divH div, #divM div, #divS div { float: left; border-right: solid 1px gray; text-align: center; } </style> </head> <body> <div> <div>Time</div> <div> <div></div> <div></div> <div></div> <div></div> </div> </div> <script type="text/javascript"> var divH = document.getElementById('divH'); var divM = document.getElementById('divM'); var divS = document.getElementById('divS'); var divTime = document.getElementById('divTime'); var aw = 2880; var ww = 400; var w = aw / 24; for (var i = 0; i < 48; i++) { var div = document.createElement('div'); div.style.width = (w - 1) + 'px'; div.innerHTML = i % 24; divH.appendChild(div); } w = aw / 60; for (var i = 0; i < 120; i++) { var div = document.createElement('div'); div.style.width = (w - 1) + 'px'; div.innerHTML = i % 60; divM.appendChild(div); } w = aw / 60; for (var i = 0; i < 120; i++) { var div = document.createElement('div'); div.style.width = (w - 1) + 'px'; div.innerHTML = i % 60; divS.appendChild(div); } window.setInterval(run, 20); function run() { var dt = new Date(); var h = dt.getHours(); var m = dt.getMinutes(); var s = dt.getSeconds(); var f = dt.getMilliseconds(); divH.style.left = ((h > 12) ? 0 : -aw) + ww / 2 + (h * -120) - m * 2 + 'px'; l = 0; divM.style.left = ((m > 30) ? 0 : -aw) + ww / 2 + (m * -48) - s / 1.2 + 'px'; l = 0; divS.style.left = ((s > 30) ? 0 : -aw) + ww / 2 + (s * -48) - f * 48 / 1000 + 'px'; divTime.innerHTML = 'Time ' + h + ':' + m + ":" + s; } </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpffd.html