|
楼主 |
kuing
发表于 2023-2-17 23:25
- <style>
- #circle {
- width: 200px;
- height: 200px;
- border-radius: 100px;
- border: 2px solid black;
- }
- #circle>div {
- width: 0px;
- height: 0px;
- }
- #sec,#min,#hour {
- position: relative;
- transform-origin: bottom;
- }
- #sec {
- width: 2px;
- left: 99px;
- height: 80px;
- top: 20px;
- background-color: red;
- }
- #min {
- width: 4px;
- left: 98px;
- height: 65px;
- top: 35px;
- background-color: blue;
- }
- #hour {
- width: 6px;
- left: 97px;
- height: 50px;
- top: 50px;
- background-color: black;
- }
- .num {
- width: 200px;
- height: 200px;
- line-height: 200px;
- text-align: center;
- }
- </style>
- <div id="circle">
- <div><div id="hour"></div></div>
- <div><div id="min"></div></div>
- <div><div id="sec"></div></div>
- </div>
- <script>
- let cc = document.getElementById("circle");
- for(let i=1;i<13;i++){
- let div = document.createElement("div");
- div.innerHTML = `<div class="num" style="transform: rotate(${30*i}deg) translate(0,-85px) rotate(${-30*i}deg);">${i}</div>`;
- cc.appendChild(div);
- }
- function time(){
- let s=document.getElementById("sec");
- let m=document.getElementById("min");
- let h=document.getElementById("hour");
- let date=new Date();
- let snum=date.getSeconds();
- let mnum=date.getMinutes()+snum/60;
- let hnum=date.getHours()+mnum/60;
- s.style.transform=`rotate(${snum*6}deg)`;
- m.style.transform=`rotate(${mnum*6}deg)`;
- h.style.transform=`rotate(${hnum*30}deg)`;
- }
- setInterval(time,1000)
- </script>
复制代码 |
|