123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <!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;
- }
- .box{
- width: 402px;
- height: 402px;
- border:1px dashed #000;
- margin:100px auto;
- }
- .clock{
- width: 400px;
- height: 400px;
- border:1px solid #000;
- border-radius: 50%;
- position: relative;
- }
- .clock li{
- list-style: none;
- width: 4px;
- height: 8px;
- background-color: #000;
- position: absolute;
- left: 50%;
- top: 0;
- margin-left: -2px;
- transform-origin: 2px 200px;
- }
- /* .clock li:nth-child(1){
- transform: rotate(0deg);
- }
- .clock li:nth-child(2){
- transform: rotate(6deg);
- }
- .clock li:nth-child(3){
- transform: rotate(12deg);
- } */
- .clock li:nth-child(5n+1){
- height: 16px;
- }
- .hours,.minute,.seconds{
- position: absolute;
- left: 50%;
- top:0;
- transform-origin:center bottom;
- }
- .clock .hours{
- margin-left: -6px;
- width: 12px;
- height: 100px;
- background-color: red;
- transform: translateY(100px);
- }
- .clock .minute{
- margin-left: -4px;
- width: 8px;
- height: 150px;
- background-color: blue;
- transform: translateY(50px);
- }
- .clock .seconds{
- margin-left: -2px;
- width: 4px;
- height: 180px;
- transform: translateY(20px);
- background-color: green;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <div class="clock">
- <!-- 刻度 -->
- <ul></ul>
- <div class="zz">
- <div class="hours"></div>
- <div class="minute"></div>
- <div class="seconds"></div>
- </div>
- </div>
- </div>
- <script>
- let oUl = document.getElementsByTagName("ul")[0];
- for(let i = 0;i<60;i++){
- let oLi = document.createElement("li");
- oLi.style.transform = `rotate(${i*6}deg)`;
- oUl.appendChild(oLi);
- }
- //控制时分秒针的旋转
- let oSeconds = document.getElementsByClassName("seconds")[0];
- let oMinutes = document.getElementsByClassName("minute")[0];
- let oHours = document.getElementsByClassName("hours")[0];
-
-
- setInterval(function(){
- let timer = new Date();
- let seconds = timer.getSeconds();
- let minutes = timer.getMinutes();
- let hours = timer.getHours();
- oSeconds.style.transform = `translateY(20px) rotate(${seconds*6}deg)`;
- oMinutes.style.transform = `translateY(50px) rotate(${minutes*6}deg)`;
- oHours.style.transform = `translateY(100px) rotate(${hours*30+minutes/2}deg)`;
- },1000);
- </script>
- </body>
- </html>
|