fengchuanyu 1 ماه پیش
والد
کامیت
19ba8f08d9
3فایلهای تغییر یافته به همراه178 افزوده شده و 0 حذف شده
  1. 55 0
      5-CSS3/6_3D效果.html
  2. 60 0
      5-CSS3/7_动画.html
  3. 63 0
      5-CSS3/练习2_时钟.html

+ 55 - 0
5-CSS3/6_3D效果.html

@@ -0,0 +1,55 @@
+<!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>
+        body{
+            /* perspective 观众距离看台距离 */
+            perspective: 1000px;
+            /* 透视原点 (观众位置) */
+            perspective-origin: center center;
+        }
+        .box{
+            width: 200px;
+            height: 200px;
+            border:2px dashed black;
+            position: relative;
+            margin: 200px auto;
+            /* 变形的样式 为3D效果 */
+            transform-style: preserve-3d;
+        }
+        .box:hover .div1{
+            transform: rotateY(180deg) translateZ(-10px);
+        }
+        .box:hover .div2{
+            transform: rotateY(180deg) translateZ(10px);
+
+        }
+        .div1,.div2{
+            position: absolute;
+            top: 0;
+            left: 0;
+            transition: all 1s linear;
+            transform-origin: left center;
+        }
+        .div1{
+            width: 200px;
+            height: 200px;
+            background-color: red;
+        }
+        .div2{
+            width: 200px;
+            height: 200px;
+            background-color: blue;
+        }
+    </style>
+</head>
+<body>
+    <div class="box">
+        <div class="div1"></div>
+        <div class="div2"></div>
+    </div>
+</body>
+</html>

+ 60 - 0
5-CSS3/7_动画.html

@@ -0,0 +1,60 @@
+<!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>
+        .box{
+            width: 200px;
+            height: 200px;
+            background-color: red;
+            /*animation 动画 后面属性分别时 动画名称 动画时间 动画速度 动画延迟 动画结束状态 */
+            /* animation: foo 2s linear 2s forwards; */
+            /* 最后一个数字动画重复次数 */
+            /* animation: foo 2s linear 2s 3; */
+            /* 动画重复次数 infinite 无限次 */
+            /* animation: foo 2s linear infinite; */
+            /* 动画名称 */
+            animation-name: foo;
+            /* 动画时间 */
+            animation-duration: 2s;
+            /* 动画速度 */
+            animation-timing-function: linear;
+            /* 动画延迟 */
+            /* animation-delay: 2s; */
+            /* 动画结束状态 */
+            /* animation-fill-mode: forwards; */
+            /* 动画播放次数 */
+            animation-iteration-count: infinite;
+
+
+        }
+        .box:hover{
+            animation-play-state: paused;
+        }
+        /* 定义动画 @keyframes 后面跟着动画名称 */
+        @keyframes foo {
+            /* 动画内容  */
+            0%{
+                transform: translateX(0);
+            }
+            50%{
+                transform: translateX(400px);
+            }
+            100%{
+                transform: translateX(0);
+            }
+            /* from{
+                transform: translateX(0);
+            }
+            to{
+                transform: translateX(200px);
+            } */
+        }
+    </style>
+</head>
+<body>
+    <div class="box"></div>
+</body>
+</html>

+ 63 - 0
5-CSS3/练习2_时钟.html

@@ -50,6 +50,37 @@
         .clock ul li:nth-child(3){
             transform: rotate(12deg);
         } */
+
+        .hour{
+            margin-left: -5px;
+            margin-top: 78px;
+            width: 10px;
+            height: 120px;
+            background-color: red;
+        }
+        .minute{
+            margin-left: -4px;
+            width: 8px;
+            height: 150px;
+            margin-top: 48px;
+            background-color: blue;
+        }
+        .second{
+            margin-left: -3px;
+            width: 6px;
+            height: 180px;
+            margin-top: 18px;
+            background-color: green;
+            /* transform: rotate(30deg); */
+        }
+        .second,.hour,.minute{
+            position: absolute;
+            left: 50%;
+            top:0;
+            transform-origin: center bottom;
+            /* transform: translateX(-50%); */
+
+        }
     </style>
 </head>
 <body>
@@ -58,11 +89,23 @@
             <ul id="clock-item">
                 
             </ul>
+            <div class="hour"></div>
+            <div class="minute"></div>
+            <div class="second"></div>
         </div>
     </div>
     <script>
         // 获取刻度容器
         var clickItem = document.getElementById("clock-item");
+        // 获取时针
+        var oHour = document.getElementsByClassName("hour");
+        oHour = oHour[0];
+        // 获取分针
+        var oMinute = document.getElementsByClassName("minute");
+        oMinute = oMinute[0];
+        // 获取秒针
+        var oSecond = document.getElementsByClassName("second");
+        oSecond = oSecond[0];
 
         // 生成刻度
         for(var i=0;i<60;i++){
@@ -73,6 +116,26 @@
             // 将创建好的li插入容器中
             clickItem.appendChild(oLi);
         }
+
+        // 控制时分秒旋转
+        function move(){
+            // 获取时间对象
+            var now = new Date();
+            // 获取时分秒
+            var hour = now.getHours();
+            var minute = now.getMinutes();
+            var second = now.getSeconds();
+
+            // 设置旋转角度
+            oSecond.style.transform = "rotate("+ (second*6) +"deg)";
+            oMinute.style.transform = "rotate("+ (minute*6) +"deg)";
+            oHour.style.transform = "rotate("+ (hour*30) +"deg)";
+        }
+        move();
+
+        // 定时器每隔一秒运行一次
+        setInterval(move,1000);
+
     </script>
 </body>
 </html>