CSS水滴效果

搬运自知乎,觉得很不错,就打算记录一下
使用纯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>动感水滴</title>
    <style>
        /* 清除默认边距 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            width: 100vw;
            height: 100vh;
            display: flex;
            background-color: #63b9e4;
            /* 设置主轴居中 */
            justify-content: center;
        }

        /* 设置水滴的样式 */
        #water {
            width: 300px;
            height: 300px;
            margin-top: 200px;
            border-radius: 50% 50% 58% 42% / 39% 48% 52% 61%;
            box-shadow: inset 10px 20px 30px rgba(0, 0, 0, 0.5),
                10px 10px 20px rgba(0, 0, 0, 0.3),
                15px 15px 30px rgba(0, 0, 0, 0.05),
                inset -10px -10px 15px rgba(255, 255, 255, 0.8);
            animation: waterDrop 3s ease-in-out infinite alternate;
        }

        /* 设置水滴上面的两个小白点为椭圆形状 */
        #water::after,
        #water::before {
            content: '';
            position: absolute;
            /* 创建渐变背景以实现颜色过渡 */
            background: white;
            border-radius: 50%;
            /* 调整为50%来创建椭圆形状 */
            box-shadow: 0 2px 2px rgba(0, 0, 0, 0.1);
        }

        #water::after {
            width: 15px;
            /* 增加宽度以形成椭圆 */
            height: 10px;
            /* 调整高度 */
            top: 240px;
            left: 48%;
            animation: waterDropShineLarge 3s ease-in-out infinite alternate;
        }

        #water::before {
            width: 30px;
            /* 增加宽度以形成椭圆 */
            height: 20px;
            /* 调整高度 */
            top: 265px;
            left: 47%;
            animation: waterDropShineSmall 3s ease-in-out infinite alternate;
        }

        /* 水滴晃动效果 */
        @keyframes waterDrop {

            0%,
            100% {
                border-radius: 50% 50% 58% 42% / 39% 48% 52% 61%;
            }

            50% {
                border-radius: 50% 50% 50% 50% / 50% 50% 50% 50%;
            }
        }

        /* 大小白点晃动效果 */
        @keyframes waterDropShineLarge {

            0%,
            100% {
                top: 240px;
                left: 48%;
            }

            50% {
                top: 235px;
                left: 49%;
            }
        }

        @keyframes waterDropShineSmall {

            0%,
            100% {
                top: 265px;
                left: 47%;
            }

            50% {
                top: 260px;
                left: 48%;
            }
        }
    </style>
</head>

<body>
    <div id="water"></div>
</body>

</html>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值