js+css3實(shí)現(xiàn)炫酷時(shí)鐘
本文實(shí)例為大家分享了js+css3實(shí)現(xiàn)炫酷時(shí)鐘的具體代碼,供大家參考,具體內(nèi)容如下
html
<body> <ul id='box'></ul> </body>
css
<style> *{ margin: 0; padding: 0; } body{ background-color: #aaa; } ul{ width: 400px; height: 400px; border: 5px solid skyblue; margin: 100px auto 0 auto; border-radius: 50%; background: radial-gradient(green 50%, yellow 100%);; position: relative; } ul li{ width: 2px; height: 15px; list-style: none; background-color: #fff; position: absolute; left: 199px; transform-origin: center 200px; } h1{ width: 2px; height: 180px; background-color: orange; position: absolute; left: 199px; top:20px; -transition: 1s linear; transform-origin: center 180px; } h2{ width: 6px; height: 160px; background-color: #fff; position: absolute; left: 197px; top:40px; transform-origin: center 160px; border-radius:20%; } h3{ width: 8px; height: 140px; background-color: #fff; position: absolute; left: 196px; top:60px; transform-origin: center 140px; transform: rotate(0deg); border-radius: 20%; } h4{ width: 30px; height: 30px; position: absolute; left: 185px; top:185px; border-radius: 50%; background-color: orange; } span{ display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; font-size: 24px; position: absolute; left: -10px; top: 28px; color: #fff; } </style>
js
(function(){ var oUl=document.getElementById('box'); var timer=null; for(var i=0,j=0;i<60;i++,j+=6){ var oLi=document.createElement('li'); oLi.style.transform='rotate('+j+'deg)'; if(i%5==0){ oLi.style.height='20px'; var oSpan=document.createElement('span'); oSpan.style.transform='rotate('+(-j)+'deg)'; if(i==0){ oSpan.innerHTML='12'; oSpan.style.fontSize='30px'; oSpan.style.left='-17px'; }else{ oSpan.innerHTML=parseInt(i/5); if(i%15==0){ oSpan.style.fontSize='36px'; } } oLi.appendChild(oSpan); } if(i==0){ var oH1=document.createElement('h1'); var oH2=document.createElement('h2'); var oH3=document.createElement('h3'); var oH4=document.createElement('h4'); oUl.appendChild(oH1); oUl.appendChild(oH2); oUl.appendChild(oH3); oUl.appendChild(oH4); } oUl.appendChild(oLi); } var oH=document.getElementsByTagName('h3')[0]; var oM=document.getElementsByTagName('h2')[0]; var oS=document.getElementsByTagName('h1')[0]; timer=setInterval(function(){ var now = new Date(); var s=now.getSeconds(); var m=now.getMinutes()+s/60; var h=now.getHours()+m/60; oS.style.transform='rotate('+s*6+'deg)'; oM.style.transform='rotate('+m*6+'deg)'; oH.style.transform='rotate('+(h%12)*30+'deg)'; },30); })();
作品截圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript獲得網(wǎng)頁(yè)窗口實(shí)際大小的示例代碼
網(wǎng)頁(yè)窗口實(shí)際大小如何獲得,可行的方法有很多,在本文將為大家介紹下使用javascript是怎樣做到的2013-09-09移動(dòng)端H5開(kāi)發(fā) Turn.js實(shí)現(xiàn)很棒的翻書(shū)效果
這篇文章主要為大家詳細(xì)介紹了Turn.js實(shí)現(xiàn)很棒的翻書(shū)效果,對(duì)Turn.js翻書(shū)效果的實(shí)現(xiàn)進(jìn)行總結(jié),感興趣的小伙伴們可以參考一下2016-06-06js 數(shù)組操作之pop,push,unshift,splice,shift
本篇文章主要介紹了js數(shù)組操作之pop,push,unshift,splice,shift。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01JS常見(jiàn)構(gòu)造模式實(shí)例對(duì)比分析
這篇文章主要介紹了JS常見(jiàn)構(gòu)造模式,結(jié)合實(shí)例形式對(duì)比分析了工廠模式、構(gòu)造函數(shù)模式、原型模式、寄生構(gòu)造函數(shù)模式、穩(wěn)妥構(gòu)造函數(shù)模式等相關(guān)概念、原理、實(shí)現(xiàn)方法與相關(guān)操作技巧,需要的朋友可以參考下2018-08-08淺談javascript六種數(shù)據(jù)類(lèi)型以及特殊注意點(diǎn)
這篇文章主要介紹了javascript六種數(shù)據(jù)類(lèi)型以及特殊注意點(diǎn),有需要的朋友可以參考一下2013-12-12js 打開(kāi)新頁(yè)面在屏幕中間的實(shí)現(xiàn)方法
下面小編就為大家?guī)?lái)一篇js 打開(kāi)新頁(yè)面在屏幕中間的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11靈活應(yīng)用js調(diào)試技巧解決樣式問(wèn)題的步驟分享
在很多時(shí)候,前端開(kāi)發(fā)人員使用JS腳本,對(duì)頁(yè)面Dom結(jié)構(gòu)或者是樣式做出了修改,會(huì)造成一些意想不到的bug2012-03-03