|
|

楼主 |
发表于 2022-3-19 17:04
|
显示全部楼层
本帖最后由 马黑黑 于 2022-3-19 17:29 编辑
代码分享:
<style type="text/css">
#kedu {
margin: 20px auto 0;
width: 20em;
height: 20em;
border: 1em solid #8B4513;
border-radius: 50%;
background: rgba(0, 0, 0, .8);
position: relative;
}
#kedu span {
position: absolute;
display: block;
width: 0.3em;
height: 0.4em;
background: rgba(0, 128, 0, .85);
left: calc(50% - 0.2em);
top: calc(50% - 0.2em);
}
#logo {
position: absolute;
font-family: Arial, '微软雅黑';
font-size: 1em;
width: 8em;
color: #111;
text-align: center;
top: 70%;
left: calc(50% - 4em);
}
#hr-hand, #min-hand, #sec-hand {
position: absolute;
transform-origin: 100%;
right: 50%;
}
#hr-hand {
width: 38%;
height: 0.3em;
background: #d2691e;
border: 0.1em solid #eee;
bottom: calc(50% - 0.25em);
}
#min-hand {
width: 42%;
height: 0.1em;
background: #eee;
bottom: calc(50% - 0.05em);
z-index: 8;
}
#sec-hand {
width: 46%;
height: 0.08em;
background: rgba(255, 0, 0, .8);
bottom: calc(50% - 0.04em);
z-index: 10;
}
#sec-hand::before {
content: "";
position: absolute;
width: 0.8em;
height: 0.8em;
background: #f5f5f5;
border-radius: 50%;
border: 0.2em solid #cd853f;
left: calc(100% - 0.5em);
top: calc(50% - 0.5em);
}
</style>
<div id="kedu">
<div id="logo">HUACHAO</div>
<div id="sec-hand"></div>
<div id="min-hand"></div>
<div id="hr-hand"></div>
</div>
<script language="javascript">
var spanStr = "";
var bigKedu, midKedu;
for(j=0; j<60; j++) {
bigKedu = (j%15 == 0 ? "width: 0.4em; background: rgba(255, 0, 0, .6);" : "");
midKedu = (j%5 != 0 ? "width: 0.2em; height: 0.2em; left: calc(50% - 0.1em); top: calc(50% - 0.1em);" : "");
spanStr += "<span style='transform: rotate(" + j*6 + "deg) translateY(-9.6em);" + bigKedu + midKedu + "'></span>";
}
document.getElementById("kedu").innerHTML += spanStr;
rTime();
setInterval(rTime, 1000);
function rTime(){
var now = new Date();
var sec = now.getSeconds();
var sDeg = ((sec / 60) * 360) + 90;
document.getElementById('sec-hand').style.transform = "rotate(" + sDeg + "deg)";
var min = now.getMinutes();
var mDeg = ((min / 60) * 360) + 90;
document.getElementById('min-hand').style.transform = "rotate(" + mDeg + "deg)";
var hr = now.getHours();
var hDeg = ((hr / 12) * 360) + ((min / 60) * 30) + 90;
document.getElementById('hr-hand').style.transform = "rotate(" + hDeg + "deg)";
}
</script>
|
|