常用css动画集合

771 阅读1分钟

1、动态进度条效果

<!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>
        .animate-wrap {
            width: 200px;
            height: 10px;
            border: 1px solid #555;
        }
        
        .animate-item {
            height: 10px;
            background-color: aqua;
            animation: slide-animate 2s ease-in-out infinite;
            transform-origin: left center;
        }
        
        @keyframes slide-animate {
            0% {
                transform: scale(0);
            }
            100% {
                transform: scale(1);
            }
        }
    </style>
</head>

<body>
    <div class="animate-wrap">
        <div class="animate-item"></div>
    </div>
</body>

</html>
        <h1 class="text-xxl">Hello world!</h1>
        <p class="text-green">Plain text</p>
    </body>
</html>

2、左右摆动动画效

<!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>
        .ver-line {
            position: relative;
            margin-left: 100px;
            top: 100%;
            width: 5px;
            height: 100px;
            background-color: #555;
            animation: swing-animate 1s ease-in-out infinite;
            transform-origin: top center;
        }
        
        @keyframes swing-animate {
            0% {
                transform: rotate(-10deg);
            }
            50% {
                transform: rotate(10deg);
            }
            100% {
                transform: rotate(-10deg);
            }
        }
    </style>
</head>

<body>
    <div class="ver-line"></div>
</body>

</html>