javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫
更新時(shí)間:2020年12月03日 12:30:46 作者:小七Plus
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了javascript實(shí)現(xiàn)時(shí)鐘動(dòng)畫的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>時(shí)針轉(zhuǎn)動(dòng)</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> * { margin: 0; padding: 0; } body, html { height: 100%; width: 100% } .t1 { width: 100%; height: 100%; background-image: radial-gradient(ellipse at 50% 70%, hsla(240, 1%, 90%, 1), hsla(225, 8%, 28%, 1)); } .t2 { position: relative; width: 100%; height: 100%; background-image: radial-gradient(farthest-side ellipse at 50% 70%, hsla(210, 1%, 78%, 0.73) 100px, rgba(150, 150, 150, 0.7) 400px, hsla(225, 4%, 18%, 0.8) 100%); z-index: -3; } .t3 { position: absolute; left: 50%; margin-left: -175px; top: 30%; height: 350px; width: 350px; border-radius: 60px; background: #fff; background-image: linear-gradient(#ffffff 40px, #ddecf2 210px, #d3e3e9); } .t3:before { content: ""; position: absolute; box-shadow: 0px -4px 3px 3px #b8bdca inset; border-radius: 60px; opacity: 0.6; height: 100%; width: 100%; -webkit-filter: blur(1px); z-index: 2; } .t3:after { content: ""; height: 17px; width: 300px; position: absolute; top: 97%; margin-left: 25px; background: #2a2a2b; -webkit-filter: blur(7px); /*Chrome, Opera*/ z-index: -1; } .t4 { position: relative; margin: 71px; width: 210px; height: 210px; border-radius: 50%; background-image: linear-gradient(#f9fdff, #d9eaf8); box-shadow: 0px 0px 28px -8px #eaf7fb; z-index: 11; font-size: 20px; ; color: #8da6b8; font-family: Arial; } .t4 i { font-style: normal } .hour { position: absolute; } .hour3 { right: 30px; top: 50%; margin-top: -7px; } .hour6 { left: 50%; bottom: 27px; margin-left: -5px; } .hour9 { left: 30px; top: 50%; margin-top: -7px; } .hour12 { left: 50%; top: 30px; margin-left: -10px; } .t4:before { content: ""; position: absolute; width: 210px; height: 210px; border-radius: 50%; box-shadow: 0px 15px 24px -5px #7a8fae; z-index: 10; } .t4:after { content: ""; left: 0px; top: 0px; position: absolute; width: 210px; height: 210px; border-radius: 50%; box-shadow: 0px 4px 4px -1px #7a8fae; z-index: 9; } #miao, #fen, #shi { position: absolute; left: 50%; height: 210px; width: 10px; margin-left: -5px; } #miao { z-index: 23; } #fen { z-index: 22; } #shi { z-index: 21; } #shi:after { content: ""; height: 60px; width: 6px; position: absolute; top: 60px; left: 2px; background: #1aa9d8; border-radius: 8px 8px 8px 8px; z-index: -1; } #fen:after { content: ""; height: 65px; width: 4px; position: absolute; top: 60px; left: 3px; background: #23bcef; border-radius: 8px 8px 8px 8px; z-index: -1; } #miao:after { content: ""; height: 80px; width: 1px; position: absolute; top: 48px; left: 4px; background: #0dc1fd; z-index: -1; } #point { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin-left: -8px; margin-top: -8px; z-index: 999; border-radius: 50%; box-shadow: 0px 3px 8px -1px #0f4873; } #point:before, #point:after { content: ""; height: 10px; width: 10px; position: absolute; top: 0%; background: #8ba3b6; border-radius: 50%; z-index: 1; } #point:before { width: 16px; height: 16px; } #point:after { background: #cee3ec; left: 3px; top: 3px; } </style> </head> <body> <div class="t2"> <!-- 時(shí)鐘的盒子 --> <div class="t3"> <!-- 時(shí)鐘區(qū)域 --> <div class="t4"> <!-- 數(shù)值 --> <i class="hour hour3">3</i> <i class="hour hour6">6</i> <i class="hour hour9">9</i> <i class="hour hour12">12</i> <!-- 時(shí)分秒的轉(zhuǎn)軸 --> <div id="miao"></div> <div id="fen"></div> <div id="shi"></div> <!-- 小圓點(diǎn) --> <div id="point"></div> </div> </div> </div> <script type="text/javascript"> // 獲取元素 var shi = document.querySelector('#shi'); var fen = document.querySelector('#fen'); var miao = document.querySelector('#miao'); setInterval(function() { var nowDate = new Date(); // 獲取時(shí)分秒 var hour = nowDate.getHours(); var minute = nowDate.getMinutes(); var second = nowDate.getSeconds(); var houerTw = hour % 12 * 30; var minuteTW = minute * 6; var secondTW = second * 6; console.log(houerTw); // 變量在拼接是要注意不能加入空格 shi.style.transform = 'rotate(' + houerTw + 'deg)'; fen.style.transform = 'rotate(' + minuteTW + 'deg)'; miao.style.transform = 'rotate(' + secondTW + 'deg)'; }, 1000) </script> </body> </html>
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- js實(shí)現(xiàn)一個(gè)簡單的數(shù)字時(shí)鐘效果
- html5 canvas js(數(shù)字時(shí)鐘)實(shí)例代碼
- 五步輕松實(shí)現(xiàn)JavaScript HTML時(shí)鐘效果
- JavaScript實(shí)現(xiàn)簡單的時(shí)鐘實(shí)例代碼
- 基于javascript實(shí)現(xiàn)動(dòng)態(tài)時(shí)鐘效果
- JavaScript實(shí)現(xiàn)抖音羅盤時(shí)鐘
- 一個(gè)簡易時(shí)鐘效果js實(shí)現(xiàn)代碼
- javascript入門·動(dòng)態(tài)的時(shí)鐘,顯示完整的一些方法,新年倒計(jì)時(shí)
- Javascript實(shí)現(xiàn)動(dòng)態(tài)時(shí)鐘效果
- JS實(shí)現(xiàn)的網(wǎng)頁倒計(jì)時(shí)數(shù)字時(shí)鐘效果
相關(guān)文章
ES6中的迭代器、Generator函數(shù)及Generator函數(shù)的異步操作方法
這篇文章主要介紹了ES6中的迭代器、Generator函數(shù)以及Generator函數(shù)的異步操作方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05JavaScript相等運(yùn)算符的九條規(guī)則示例詳解
這篇文章主要給大家介紹了關(guān)于JavaScript相等運(yùn)算符的九條規(guī)則,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10分享JavaScript與Java中MD5使用兩個(gè)例子
這篇文章主要為大家分享了JavaScript與Java中MD5使用兩個(gè)例子,2015-12-12JavaScript進(jìn)階(二)詞法作用域與作用域鏈實(shí)例分析
這篇文章主要介紹了JavaScript詞法作用域與作用域鏈,結(jié)合實(shí)例形式分析了JavaScript詞法作用域與作用域鏈相關(guān)概念、原理與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05使用JS實(shí)現(xiàn)鼠標(biāo)放上圖片進(jìn)行放大離開實(shí)現(xiàn)縮小功能
這篇文章主要介紹了使用JS實(shí)現(xiàn)鼠標(biāo)放上圖片進(jìn)行放大離開實(shí)現(xiàn)縮小功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01