水波涟漪效果


点击在线体验
Github地址

效果展示

点击在线体验
Github地址

在这里插入图片描述

代码实现

HTML+JS

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

<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>
    <link rel="stylesheet" href="index.css">
</head>

<body>
    <div class="box">
        <span>welcome</span>
        <span>coderbin.link</span>
    </div>
    <script>
        const spans = document.querySelectorAll('.box span');
        spans.forEach(span => {
            span.addEventListener('click', function(e) {
                let posX = e.pageX - e.target.offsetLeft;
                let posY = e.pageY - e.target.offsetTop;
                const i = document.createElement('i');
                i.style.left = posX + 'px';
                i.style.top = posY + 'px';
                this.appendChild(i);
                setTimeout(() => {
                    this.removeChild(i);
                }, 2000)

            })
        })
    </script>
</body>

</html>

CSS

body {
    height: 100vh;
    background-color: #232323;
    display: flex;
    justify-content: center;
    align-items: center;
}

.box {
    height: 100px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.box span {
    position: relative;
    display: inline-block;
    height: 35px;
    line-height: 35px;
    color: #fff;
    text-transform: uppercase;
    padding: 0 20px;
    overflow: hidden;
    letter-spacing: 2px;
    margin-right: 50px;
    border-radius: 17.5px;
}

.box span:nth-child(1) {
    background: linear-gradient(to right, #755bea, #ff72c0);
}

.box span:nth-child(2) {
    background: linear-gradient(to right, #0162c8, #55e7fc);
}

.box span i {
    display: block;
    position: absolute;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background-color: #fff;
    animation: move 2s linear 0s 1;
    pointer-events: none;
}

@keyframes move {
    0% {
        width: 0;
        height: 0;
        opacity: .5;
    }
    100% {
        width: 500px;
        height: 500px;
        opacity: 0;
    }
}
  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值