本文實(shí)例講述了JS+CSS3實(shí)現(xiàn)的簡(jiǎn)易鐘表效果。分享給大家供大家參考,具體如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>www.jb51.net js+css3簡(jiǎn)易鐘表</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#wrap{
width: 300px;
height: 300px;
background-color: aliceblue;
margin: 200px auto;
position: relative;
box-sizing: border-box;
}
#wrap > div{
position: absolute;
top: 50%;
left: 50%;
}
#hour{
width: 6px;
height: 60px;
background-color: #000000;
margin: -60px -3px;
transform-origin: 3px 60px;
}
#min{
width: 4px;
height: 80px;
background-color: #000000;
margin: -80px -2px;
transform-origin: 2px 80px;
}
#sec{
width: 2px;
height: 100px;
background-color: red;
margin: -100px -1px;
transform-origin: 1px 100px;
}
#point{
width: 20px;
height: 20px;
background-color: burlywood;
margin: -10px -10px;
border-radius: 50%;
}
#circle{
width: 300px;
height: 300px;
position: relative;
}
#circle li{
list-style: none;
width: 2px;
height: 6px;
background-color: #000000;
position: absolute;
transform-origin: 1px 150px;
left: 149px;
top: 0px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="hour"></div>
<div id="min"></div>
<div id="sec"></div>
<div id="point"></div>
<ul id="circle"></ul>
</div>
</body>
<script type="text/javascript">
var hourDom=document.getElementById('hour');
var minDom=document.getElementById('min');
var secDom=document.getElementById('sec');
var cricle=document.getElementById('circle');
//創(chuàng)建表盤(pán),ul寬高為wrap寬高,以wrap中心點(diǎn)為變換基點(diǎn),動(dòng)態(tài)分配6°的li
for (var i=0;i<60;i++) {
var li=document.createElement('li');
cricle.appendChild(li);
li.style.transform='rotate('+i*6+'deg)';
}
//延時(shí)函數(shù),確保每一秒更新一次最新時(shí)間。并且計(jì)算時(shí)間準(zhǔn)確值。
setInterval(function(){
var date=new Date();
var hour=date.getHours();
var min=date.getMinutes();
var sec=date.getSeconds();
min+=sec/60;
hour+=min/60;
//當(dāng)前時(shí)間*每個(gè)單位時(shí)間走的角度=指針指向
hourDom.style.transform='rotate('+hour*30+'deg)';
minDom.style.transform='rotate('+min*6+'deg)';
secDom.style.transform='rotate('+sec*6+'deg)';
},1000)
</script>
</html>
網(wǎng)站標(biāo)題:JS+CSS3實(shí)現(xiàn)的簡(jiǎn)易鐘表效果示例-創(chuàng)新互聯(lián)
URL地址:http://chinadenli.net/article20/dspgjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)、定制網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、用戶體驗(yàn)、微信小程序、全網(wǎng)營(yíng)銷(xiāo)推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容