国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

用JavaScript實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)時(shí)鐘

瀏覽:71日期:2023-12-02 14:00:40

利用JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)時(shí)鐘,效果如下圖所示:

用JavaScript實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)時(shí)鐘

首先在body中完成表盤、指針的資源載入:

<div><img src='http://www.cgvv.com.cn/image/clockface.jpg' alt=''></div><hr ><hr id='min'><hr id='second'>

設(shè)置CSS樣式:

<style>body{ margin: 0;}div{ margin: 0 auto; width: 600px; height: 600px;}#hour{ background-color: black; width: 130px; height: 10px; position: fixed; top: 295px; left: 50%; margin-left: -65px;}#min{ background-color: red; width: 200px; height: 8px; position: fixed; top: 296px; left: 50%; margin-left: -100px;}#second{ background-color: yellow; width: 270px; height: 5px; position: fixed; top: 297.5px; left: 50%; margin-left: -135px;}</style>

最后是JS代碼部分,使用循環(huán)定時(shí)器setInterval()每秒調(diào)用一次主函數(shù),主函數(shù)內(nèi)使用new Date()創(chuàng)建時(shí)間對(duì)象,分別使用 .getHours();.getMinutes();.getSeconds()獲得當(dāng)前的時(shí)分秒,然后利用CSS自帶動(dòng)畫-旋轉(zhuǎn)改變指針的角度:

setInterval(watch,1000);var anjleSeconds=0,anjleMin=0,anjleHours=0;function watch() {var Time= new Date();anjleSeconds=Time.getSeconds()/60*360+90;anjleMin=Time.getMinutes()/60*360+90;anjleHours=nowHours/12*360+90;document.getElementById('second').style.transform='rotate('+anjleSeconds+'deg)';document.getElementById('min').style.transform='rotate('+anjleMin+'deg)';document.getElementById('hour').style.transform='rotate('+anjleHours+'deg)'; }

目前存在的問(wèn)題是,時(shí)分秒指針由于使用的是hr標(biāo)簽表示,所以存在兩端一樣長(zhǎng)的問(wèn)題。

完整代碼如下:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style>body{ margin: 0;}div{ margin: 0 auto; width: 600px; height: 600px;}#hour{ background-color: black; width: 130px; height: 10px; position: fixed; top: 295px; left: 50%; margin-left: -65px;}#min{ background-color: red; width: 200px; height: 8px; position: fixed; top: 296px; left: 50%; margin-left: -100px;}#second{ background-color: yellow; width: 270px; height: 5px; position: fixed; top: 297.5px; left: 50%; margin-left: -135px;} </style></head><body><div><img src='http://www.cgvv.com.cn/image/clockface.jpg' alt=''></div><hr ><hr id='min'><hr id='second'><script> setInterval(watch,1000); var anjleSeconds=0,anjleMin=0,anjleHours=0; function watch() {var Time= new Date();anjleSeconds=Time.getSeconds()/60*360+90;anjleMin=Time.getMinutes()/60*360+90;anjleHours=Time.getHours()/12*360+90;document.getElementById('second').style.transform='rotate('+anjleSeconds+'deg)';document.getElementById('min').style.transform='rotate('+anjleMin+'deg)';document.getElementById('hour').style.transform='rotate('+anjleHours+'deg)'; }</script></body></html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 色综合a | 中文日韩字幕一区在线观看 | 亚洲理论欧美理论在线观看 | 欧美在线不卡 | 手机在线免费看毛片 | 另类视频欧美 | 久久不见久久见免费影院 | 日本www色视频成人免费网站 | 免费一级肉体全黄毛片高清 | 国产三级国产精品国产国在线观看 | 国产一区二区三区四区五区 | 成人男女啪啪免费观看网站 | 日本色综合网 | xxxxx亚洲| 手机在线看片福利 | 亚洲国产成人91精品 | 欧美久久久久欧美一区 | 欧美高清视频一区 | 亚洲欧美字幕 | 久久精品99精品免费观看 | 真实国产普通话对白乱子子伦视频 | 亚洲精品久久九九精品 | 看一级毛片国产一级毛片 | 国产日韩精品一区在线观看播放 | 深夜福利视频在线观看免费视频 | 精品视频免费在线观看 | 亚洲福利视频一区二区三区 | 久久久久久91精品色婷婷 | 成人免费在线播放 | 欧美一级欧美三级在线观看 | 波多野结衣一区二区在线 | 国产一级淫片a免费播放口之 | 欧美午夜精品一区二区三区 | 成人精品第一区二区三区 | 91成人在线免费观看 | 国产特级全黄一级毛片不卡 | aaaaaa精品视频在线观看 | 亚洲高清视频在线观看 | 亚洲欧美国产中文 | 99久久精品国产片久人 | 美女被免费网站在线视频软件 |