css制作一个简单的上下跳动 动画

在这里插入图片描述
如果只是简单的几个小动画 确实没必要引入一个动画库 去做 除非你的项目中很需要各种各样的动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div.parent {
      
      
            display: flex;
        }
        .child {
      
      
            height: 50px;
            width: 200px;
            background-color: #aaf;
            text-align: center;
            line-height: 50px;
            border-radius: 16px;
            position: relative;
            top: 100px;
            left: 50%;
            transform: translateX(-50%);
            transition: all 1s;
            animation: jump .5s ease-in-out infinite alternate;
        }
        .child::after {
      
      
            content: "";
            height: 0;
            width: 0;
            position: absolute;
            bottom: -20px;
            left: 50%;
            transform: translateX(-50%);
            border: 10px solid;
            border-color: #aaf transparent transparent transparent;
        }
        @keyframes jump {
      
      
            from {
      
       top: 100px; }
            to {
      
       top: 120px }
        }
    </style>
</head>
<body>
    <div class="parent">
        <div class="child">
            一个简单的跳动动画
        </div>
    </div>
</body>
</html>

关注我 持续更新前端知识。

猜你喜欢

转载自blog.csdn.net/yunchong_zhao/article/details/122609951