123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- ul{
- margin: 0;
- padding: 0;
- }
- li{
- list-style: none;
- }
- .box{
- width: 402px;
- height: 402px;
- border:1px dashed black;
- margin: 100px auto;
- }
- .clock{
- width: 400px;
- height: 400px;
- border: 1px solid black;
- border-radius: 50%;
- position: relative;
- transform: rotate(180deg);
- }
- .clock li{
- width: 4px;
- height: 8px;
- background-color: #000;
- position: absolute;
- top: 0;
- left: 50%;
- transform-origin: 0 200px;
- }
- .clock li:nth-child(5n + 1){
- height: 16px;
- }
- .clock div{
- position: absolute;
- top: 200px;
- left: 50%;
- margin-left: -2px;
- /* transform: translateY(-100%); */
- transform-origin: 0 0;
- }
- .hour{
- width: 4px;
- height: 80px;
- background-color: red;
- }
- .minute{
- width: 4px;
- height: 120px;
- background-color: blue;
- }
- .seconds{
- width: 4px;
- height: 160px;
- background-color: green;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <div class="clock">
- <ul>
-
- </ul>
- <div class="seconds"></div>
- <div class="minute"></div>
- <div class="hour"></div>
- </div>
- </div>
- <script>
- let oUl = document.getElementsByTagName("ul")[0];
- let oSecond = document.getElementsByClassName("seconds")[0];
- let oMinute = document.getElementsByClassName("minute")[0];
- let oHour = document.getElementsByClassName("hour")[0];
- for(let i=0;i<60;i++){
- let oLi = document.createElement("li");
- oLi.style.transform = `rotate(${i*6}deg)`;
- oUl.append(oLi);
- }
- setInterval(() => {
- let nowTimer = new Date();
- let second = nowTimer.getSeconds();
- let minute = nowTimer.getMinutes();
- let hour = nowTimer.getHours();
- console.log(second);
- oSecond.style.transform = `rotate(${second*6}deg)`;
- oMinute.style.transform = `rotate(${minute*6}deg)`;
- oHour.style.transform = `rotate(${hour*30}deg)`;
- }, 1000);
- </script>
- </body>
- </html>
|