CSS 门铰效果

CSS 门铰效果

描述

元素可以通过突然的快速运动翻转或导致翻转。

语法

@keyframes hinge {
   0% { 
      transform: rotate(0); 
      transform-origin: top left; 
      animation-timing-function: ease-in-out; 
   }
   20%, 60% { 
      transform: rotate(80deg); 
      transform-origin: top left; 
      animation-timing-function: ease-in-out; 
   }
   40% { 
      transform: rotate(60deg); 
      transform-origin: top left; 
      animation-timing-function: ease-in-out; 
   }
   80% { 
      transform: rotate(60deg) translateY(0); 
      opacity: 1; 
      transform-origin: top left; 
      animation-timing-function: ease-in-out; 
   }
   100% { 
      transform: translateY(700px); 
      opacity: 0; 
   } 
}

参数

  • transform − 变换将2D和3D变换应用于元素。

  • opacity − 不透明度用于使元素半透明。

示例

<html>
   <head>
      <style>
         .animated {
            background-image: url(https://geek-docs.com/static/logo.png);
            background-repeat: no-repeat;
            background-position: left top;
            padding-top:95px;
            margin-bottom:60px;
            -webkit-animation-duration: 1s;
            animation-duration: 1s;
            -webkit-animation-fill-mode: both;
            animation-fill-mode: both;
         }

         @-webkit-keyframes hinge {
            0% {
               -webkit-transform: rotate(0);
               -webkit-transform-origin: top left; 
               -webkit-animation-timing-function: ease-in-out;
            }
            20%, 60% {
               -webkit-transform: rotate(80deg); 
               -webkit-transform-origin: top left; 
               -webkit-animation-timing-function: ease-in-out;
            }
            40% {
               -webkit-transform: rotate(60deg);
               -webkit-transform-origin: top left;
               -webkit-animation-timing-function: ease-in-out;
            }
            80% {
               -webkit-transform: rotate(60deg) translateY(0);
               opacity: 1; 
               -webkit-transform-origin: top left; 
               -webkit-animation-timing-function: ease-in-out;
            }
            100% {
               -webkit-transform: translateY(700px);
               opacity: 0;
            }
         }

         @keyframes hinge {
            0% { 
               transform: rotate(0); 
               transform-origin: top left; 
               animation-timing-function: ease-in-out; 
            }
            20%, 60% { 
               transform: rotate(80deg); 
               transform-origin: top left; 
               animation-timing-function: ease-in-out; 
            }
            40% { 
               transform: rotate(60deg); 
               transform-origin: top left; 
               animation-timing-function: ease-in-out;
            }
            80% { 
               transform: rotate(60deg) translateY(0); 
               opacity: 1; 
               transform-origin: top left; 
               animation-timing-function: ease-in-out; 
            }
            100% { 
               transform: translateY(700px); 
               opacity: 0; 
            }
         }

         .hinge {
            -webkit-animation-name: hinge;
            animation-name: hinge;
         }
      </style>
   </head>

   <body>

      <div id = "animated-example" class = "animated hinge"></div>
      <button onclick = "myFunction()">Reload page</button>

      <script>
         function myFunction() {
            location.reload();
         }
      </script>

   </body>
</html>

它将产生以下结果−

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程