原生js實(shí)現(xiàn)可愛糖果數(shù)字時間特效
效果展示:http://demo.jb51.net/js/2016/js_hovertreecolortime/
源碼下載:http://xiazai.jb51.net/201612/yuanma/hovertreecolortime_jb51.rar
數(shù)字采用漂亮的糖果皮膚設(shè)計(jì)
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>js多彩的數(shù)字時鐘_何問起</title><base target="_blank" /> <style>a{color:blue;}</style> </head> <body> <div><h1>JS實(shí)現(xiàn)多彩的數(shù)字時鐘</h1></div> <div id="time"></div> <div><br /><br /><a >何問起</a> <a >說明</a> <a >特效</a></div> <script> function getTime(){ var date = new Date(); var hours =formatTime(date.getHours()); var minutes = formatTime(date.getMinutes()); var seconds = formatTime(date.getSeconds()); var $time = document.getElementById('time'); $time.innerHTML=hours +"<img src='images/hm.png' style='margin:0 10px;' width='12' height='40'/>"+ minutes+"<img style='margin:0 10px;' src='images/ms.png' width='12' height='40'/>"+ seconds; setTimeout("getTime()",500); } function formatTime(i){ if(i<10&&i==1){ i= "<img src='images/0.png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>"; }else if(i<10&&i!=1){ i= "<img src='images/0.png' width='40' height='60'/>" + "<img src='images/"+i+".png' width='40' height='60'/>"; }else{ var j= i.toString().charAt(0); var z =i.toString().charAt(1); if(j<10 && z<10&&j!=1&&z!=1){ i = "<img src='images/"+j+".png' width='40' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>"; }else if(j<10 && z<10&&j==1&&z!=1){ i = "<img src='images/1.png' width='20' height='60'/>" + "<img src='images/"+z+".png' width='40' height='60'/>"; }else if(j<10 && z<10&&z==1&&j!=1){ i = "<img src='images/"+j+".png' width='40' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>"; }else if(j<10 && z<10&&(j==1&&z==1)){ i="<img src='images/1.png' width='20' height='60'/>"+"<img src='images/1.png' width='20' height='60'/>"; } } return i; } getTime(); </script> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
iframe實(shí)現(xiàn)與父頁面跨域隔離的JavaScript?代碼沙箱
這篇文章主要介紹了使用iframe實(shí)現(xiàn)與父頁面跨域隔離的JavaScript代碼沙箱,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05JavaScript中的構(gòu)造函數(shù)和實(shí)例對象之間的關(guān)系(構(gòu)造器)
這篇文章主要介紹了JavaScript中的構(gòu)造函數(shù)和實(shí)例對象之間的關(guān)系(構(gòu)造器),需要的朋友可以參考下2023-05-05javascript自定義右鍵彈出菜單實(shí)現(xiàn)方法
這篇文章主要介紹了javascript自定義右鍵彈出菜單實(shí)現(xiàn)方法,涉及javascript操作鼠標(biāo)事件及頁面元素的相關(guān)技巧,需要的朋友可以參考下2015-05-05基于VSCode調(diào)試網(wǎng)頁JavaScript代碼過程詳解
這篇文章主要介紹了基于VSCode調(diào)試網(wǎng)頁JavaScript代碼過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07將json轉(zhuǎn)換成struts參數(shù)的方法
下面小編就為大家?guī)硪黄獙son轉(zhuǎn)換成struts參數(shù)的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11JavaScript字符串轉(zhuǎn)數(shù)字的5種方法及遇到的坑
JavaScript是一個神奇的語言,字符串轉(zhuǎn)數(shù)字有5種方法,各有各的坑法!接下來通過本文給大家介紹JavaScript字符串轉(zhuǎn)數(shù)字的5種方法及其陷阱,感興趣的朋友一起看看吧2018-07-07