CSS3弹窗动画效果

时间:2022-07-24
本文章向大家介绍CSS3弹窗动画效果,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

弹窗从上到下动画

.fadein {
    animation: fadein .5s;
}
@keyframes fadein {
    0% {
        transform: translate(0, -100%);
    }
    100% {
        transform: none;
    }
}

弹窗从下到上动画

.fadein {
    animation: fadein .5s;
}
@keyframes fadein {
    0% {
        transform: translate(0, 100%);
    }
    100% {
        transform: none;
    }
}

弹窗从右向左动画

.fadein {
    animation: fadein .5s;
}
@keyframes fadein {
    0% {
        transform: translate(100%, 0);
    }
    100% {
        transform: none;
    }
}

弹窗从左向右动画

.fadein {
    animation: fadein .5s;
}
@keyframes fadein {
    0% {
        transform: translate(-100%, 0);
    }
    100% {
        transform: none;
    }
}

通过改变css属性也可以达到类似效果

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .top {
            position: fixed;
            top: -200px;
            left: 0;
            width: 100%;
            height: 200px;
            background: silver;
        }

        .fade {
            transition: all .6s;
        }

        .control {
            position: fixed;
            bottom: 0;
            left: 0;
            color: #fff;
            font-size: 40px;
            width: 100%;
            height: 150px;
            display: flex;
            cursor: pointer;
        }

        .control div {
            width: 50%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .in {
            background: steelblue;
        }

        .out {
            background: grey;
        }
    </style>
</head>

<body>
    <div class="top fade"></div>
    <div class="control">
        <div class="in">显示</div>
        <div class="out">隐藏</div>
    </div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
    $('.in').click(function () {
        $('.top').css('top', '0')
    })
    $('.out').click(function () {
        $('.top').css('top', '-200px')
    })
</script>

</html>