JavaScript實(shí)現(xiàn)簡(jiǎn)單日期特效
JavaScript之日期特效的具體代碼,供大家參考,具體內(nèi)容如下
直接上代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> *{ padding: 0; margin: 0; } #date{ width: 450px; height: 300px; background-color: darkorange; border-radius: 10px; margin: 100px auto; } #nowDate{ width: 450px; height: 60px; line-height: 60px; text-align: center; color: #fff; font-size: 26px; } #day{ width: 200px; height: 200px; line-height: 200px; background-color: orchid; margin: 0 auto; text-align: center; } </style> </head> <body> <div id="date"> <p id="nowDate"></p> <p id="day"></p> </div> <script type="text/javascript"> // 獲取標(biāo)簽 var nowDate = document.getElementById("nowDate"); var day = document.getElementById("day"); // 用定時(shí)器 更新時(shí)間的變化 setInterval(nowNumTime,1000); nowNumTime(); function nowNumTime(){ var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); var temp = '' + (hour>12 ? hour-12:hour); var year = now.getFullYear(); var month = now.getMonth(); var d = now.getDate(); var week = now.getDay(); console.log(week); //索引 var weeks = ["星期天","星期一","星期二","星期三","星期四","星期五","星期六"]; // console.log(temp); if (hour ===0){ temp = '12'; } temp = temp + (minute <10 ? ':0':":"+minute); temp = temp + (second <10 ? ':0':":"+second); temp = temp + (hour>=12 ? ' P.M.':' A.M.'); temp = `${year}年${month}月$ublnpf9mb日 ${temp}${weeks[week]}`; // console.log(temp); nowDate.innerHTML = temp; } </script> </body> </html>
實(shí)現(xiàn)效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于HTML5上使用iScroll實(shí)現(xiàn)下拉刷新,上拉加載更多
本文主要介紹在HTML5中使用iScroll實(shí)現(xiàn)下拉刷新,上拉加載更多數(shù)據(jù)的方法,主要就是寫了兩個(gè)自定義函數(shù)pullDownAction和pullUpAction,分別在下拉和上拉的事件中調(diào)用他們。2016-05-05JS交互點(diǎn)擊WKWebView中的圖片實(shí)現(xiàn)預(yù)覽效果
這篇文章主要介紹了JS交互點(diǎn)擊WKWebView中的圖片實(shí)現(xiàn)預(yù)覽效果,需要的朋友可以參考下2018-01-01JavaScript中number轉(zhuǎn)換成string介紹
這篇文章主要介紹了JavaScript中number轉(zhuǎn)換成string介紹,本文講解了4個(gè)把number轉(zhuǎn)換成string的函數(shù),需要的朋友可以參考下2014-12-12js canvas實(shí)現(xiàn)放大鏡查看圖片功能
這篇文章主要為大家詳細(xì)介紹了js canvas實(shí)現(xiàn)放大鏡查看圖片功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06關(guān)于js獲取radio和select的屬性并控制的代碼
對(duì)于聯(lián)動(dòng)菜單大家都不會(huì)陌生了,但是這還是我第一次寫聯(lián)動(dòng)的了。原理很簡(jiǎn)單,但是自己寫起來(lái)就感覺還是有點(diǎn)難度的了2011-05-05javascript實(shí)現(xiàn)點(diǎn)亮燈泡特效示例
這篇文章主要介紹了javascript實(shí)現(xiàn)點(diǎn)亮燈泡特效示例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10使用JS前端技術(shù)實(shí)現(xiàn)靜態(tài)圖片局部流動(dòng)效果
本文使用前端開發(fā)技術(shù),結(jié)合?SVG?和?CSS?來(lái)實(shí)現(xiàn)類似的液化流動(dòng)效果,包含的知識(shí)點(diǎn)主要包括:mask-image?遮罩、feTurbulence?和?feDisplacementMap?濾鏡、filter?屬性、canvas?繪制方法、TimelineMax?動(dòng)畫及input[type=file]?本地圖片資源加載,需要的朋友可以參考下2022-08-08