本文实例讲述了JS+CSS3实现的简易钟表效果。分享给大家供大家参考,具体如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>www.jb51.net js+css3简易钟表</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');
//创建表盘,ul宽高为wrap宽高,以wrap中心点为变换基点,动态分配6°的li
for (var i=0;i<60;i++) {
var li=document.createElement('li');
cricle.appendChild(li);
li.style.transform='rotate('+i*6+'deg)';
}
//延时函数,确保每一秒更新一次最新时间。并且计算时间准确值。
setInterval(function(){
var date=new Date();
var hour=date.getHours();
var min=date.getMinutes();
var sec=date.getSeconds();
min+=sec/60;
hour+=min/60;
//当前时间*每个单位时间走的角度=指针指向
hourDom.style.transform='rotate('+hour*30+'deg)';
minDom.style.transform='rotate('+min*6+'deg)';
secDom.style.transform='rotate('+sec*6+'deg)';
},1000)
</script>
</html>
运行效果:
感兴趣的朋友可使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试一下运行效果。
PS:这里再为大家推荐几款时间及日期相关工具供大家参考使用:
在线日期/天数计算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi
在线日期计算器/相差天数计算器:
http://tools.jb51.net/jisuanqi/datecalc
在线日期天数差计算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq
Unix时间戳(timestamp)转换工具:
http://tools.jb51.net/code/unixtime
更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript时间与日期操作技巧总结》、《JavaScript查找算法技巧总结》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript遍历算法与技巧总结》及《JavaScript数学运算用法总结》
希望本文所述对大家JavaScript程序设计有所帮助。
JS,CSS3,钟表
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新动态
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
