fengchuanyu 2 mēneši atpakaļ
vecāks
revīzija
87df38d6b4
1 mainītis faili ar 54 papildinājumiem un 4 dzēšanām
  1. 54 4
      8_CSS3/练习题1_时钟.html

+ 54 - 4
8_CSS3/练习题1_时钟.html

@@ -30,7 +30,8 @@
             position: absolute;
             left: 50%;
             top: 0;
-            transform-origin: 0 200px;
+            margin-left: -2px;
+            transform-origin: 2px 200px;
         }
         /* .clock li:nth-child(1){
             transform: rotate(0deg);
@@ -44,14 +45,45 @@
         .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>
+            <!-- 刻度 -->
+            <ul></ul>
+            <div class="zz">
+                <div class="hours"></div>
+                <div class="minute"></div>
+                <div class="seconds"></div>
+            </div>
         </div>
     </div>
     <script>
@@ -61,6 +93,24 @@
             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}deg)`;
+        },1000);
     </script>
 </body>
 </html>