web前端一起努力Web

CSS之过渡,形变转换及动画

2018-11-22  本文已影响0人  追逐_chase
web.jpg

过渡(transition)

<style>
        
        div{
          width: 200px;
          height: 200px;
          background-color: pink;  
          transition: width 0.5s linear 1s ;
        }

        div:hover{
            width: 600px;
            height: 700px;;
        }
    
    </style>
transition.gif

transform 变形

2D形变

-transform可以 实现元素的位移、旋转、倾斜、缩放

   <style>
       
       div{
         width: 200px;
         height: 200px;
         background-color: pink; 
          transition: all 0.5s;
       }

       div:hover{
           transform: translateX(50%);
           /* 50% 走 自己宽度的一半 */
       }
   
   </style>

110.gif
 position: absolute;
          left: 50%;
          top: 0;
          /* margin-left: -100px; */
          transform: translateX(-50%);
 div{
        width: 300px;
        height: 300px;
        background-color: pink;
    }
    div img {
        transition: all 0.2s;
        
    }

    div img:hover{
        transform: scale(2);
    }
    
    </style>
110.gif
 <style>
     div{
         width: 200px;
         height: 200px;
         background-color: pink;
         margin: 100PX auto;
         transition: all 0.5s;

        
        }

        div:hover{
            transform: rotate(45deg); 
        }
    </style>

110.gif

3D旋转效果


 <style>
     div{
         width: 200px;
         height: 200px;
        
         margin: 100PX auto;
         transition: all 1s;
         background-color: #036663;
        
        }

        div:hover{
            transform: rotateX(360deg); 
           
        }
    </style>

rotateX.gif
  div{
         width: 200px;
         height: 200px;
        
         margin: 100PX auto;
         transition: all 1s;
         background-color: #036663;
        
        }

 div:hover{
            transform: rotateY(360deg); 
           
        }

rotateY.gif
  div{
         width: 200px;
         height: 200px;
        
         margin: 100PX auto;
         transition: all 1s;
         background-color: #036663;
        
        }

 div:hover{
            transform: rotateZ(360deg); 
           
        }
rotateZ.gif
   body{
            perspective: 500px;
        }
     div{
         width: 200px;
         height: 200px;
        
         margin: 100PX auto;
         transition: all 1s;
         background-color: #036663;
        
        }
 div:nth-child(4):hover{
            transform: translate3d(100px,100px, 50px);
        }
110.gif

综合例子

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <style>
        section {
            width: 450px;
            height: 300px;
            background: url("./images/1.jpg") no-repeat;
            margin: 100px auto;
            border: 1px solid #000000;
            position: relative;
            /* 视距 */
            perspective: 1000px;
            /* 过渡 */
            transition: all 0.5s linear;
        }
        .door_left,
        .door_right{
           width: 50%;
           height: 100%;
           background-color: pink; 
           position: absolute;
           top: 0;
           transition: all 0.5s linear;
           
        }
        .door_left {
            left: 0;
            border-right: 1px solid #000000;
            /* 设置旋转的点 */
            transform-origin: 0px center;
        }

        .door_right{
            right: 0;
            border-left: 1px solid #000000;
            transform-origin:100% center;
        }

        .door_left::before,
        .door_right::before {
            content: "";
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: 1px solid #ffffff;
            position: absolute;
            top: 50%;
        }

        .door_left::before {
            right: 5px;
          /* 居中对齐 */
            transform: translateY(-50%);
        }

         .door_right::before {
            left: 5px;
            transform: translateY(-50%);
        }
      
        section:hover .door_left {
           
            transform: rotateY(-120deg);
        }
        section:hover .door_right{
           
            transform: rotateY(120deg);
            
        }
       

    
    </style>
</head>
<body>
    <section>
        <div class="door_left"></div>
        <div class="door_right"></div>
        
    </section>
</body>
</html>
110.gif

动画 animation

<style>
        div{
            width: 200px;
            height: 200px;
            background-color: blueviolet;
            animation: chang 2s linear 0s 2 reverse;
        }
        /* 定义动画 */
        @keyframes chang{
            from{
                transform: translateX(0);
            }

            to {
                transform: translateX(100px);
            }
        }
    
    </style>
animation.gif

喜欢文章的👍一下,谢谢,有想学习[web]可以私聊我。

image.png
上一篇 下一篇

猜你喜欢

热点阅读