时间:2021-07-15 09:30:48 | 栏目:JavaScript代码 | 点击:次
本文实例为大家分享了js实现数码时钟效果展示的具体代码,供大家参考,具体内容如下
代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>数码时钟2</title> <style type="text/css"> *{ background-color: rgb(7,110,177); vertical-align: middle; } #div1{ text-align: center; width: 1300px; height: 220px; margin:0 auto; } span{ font-size: 50px; color: white; } </style> <script type="text/javascript"> window.onload=function() { var aImg = document.getElementsByTagName('img'); function tick() { var oDate = new Date(); var str = toDbl(oDate.getHours())+toDbl(oDate.getMinutes())+toDbl(oDate.getSeconds()); for (var i = 0; i < aImg.length; i++) { aImg[i].src='images/'+str.charAt(i)+'.jpg'; }; }; setInterval(tick,500); tick(); }; function toDbl(n) { if (n<10) { return '0'+n; } else { return ''+n; } }; </script> </head> <body> <div id="div1"> <img src="images/1.jpg"> <img src="images/2.jpg"> <span>:</span> <img src="images/3.jpg"> <img src="images/4.jpg"> <span>:</span> <img src="images/5.jpg"> <img src="images/6.jpg"> </div> </body> </html>
更多JavaScript时钟特效点击查看:JavaScript时钟特效专题