CSS - Efecto de bisagra

Descripción

Un elemento puede volcarse o hacer que se dé la vuelta con un movimiento rápido y repentino.

Sintaxis

@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; 
   } 
}

Parámetros

  • Transform - La transformación se aplica a la transformación 2d y 3d de un elemento.

  • Opacity - La opacidad se aplica a un elemento para hacer translucidez.

Ejemplo

<html>
   <head>
      <style>
         .animated {
            background-image: url(/css/images/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>

Producirá el siguiente resultado: