css —— 按钮水波纹扩散动画效果实现

一. 效果

​​​​​​​

 

二. 代码

<div class="feature">
        <div class="feature-box">
            <div class="pulse"></div>
            <div class="pulse1"></div>
            <div class="pulse2"></div>
        </div>
    </div>

<style>
        .feature {
			width: 100%;
            height: 800px;
			display: flex;
			align-items: center;
			justify-content: center;
        }
        .feature-box {
            width: 140px;
            height: 140px;
            margin-top: -30%;
            position: relative;
            z-index: 2;
        }
		.pulse {
            width: 140px;
            height: 140px;
            background: #4892FB;
            border-radius: 50%;
        }
        .pulse1, .pulse2 {
            position: absolute;
            width: 180px;
            height: 180px;
            left: 50%;
            top: -20px;
            margin-left: -90px;
            background: #4892FB;
            border-radius: 50%;
            opacity: 0;
            z-index: -1;
            box-shadow: 1px 1px 15px #3399ff;
        }
        .pulse1 {
            animation: warn1 1.5s linear;
            animation-iteration-count: infinite;
        }
        .pulse2 {
            animation: warn2 1.5s linear;
            animation-iteration-count: infinite;
        }
        @keyframes warn1 {
		0% {
			transform: scale(1);
			opacity: 0.01;
		}

		25% {
			transform: scale(1.2);
			opacity: 0.1;
		}

		50% {
			transform: scale(1.4);
			opacity: 0.07;
		}

		75% {
			transform: scale(1.6);
			opacity: 0.03;
		}

		100% {
			transform: scale(1.8);
			opacity: 0.01;
		}
	}

	@keyframes warn2 {
		0% {
			transform: scale(0.8);
			opacity: 0.01;
		}

		25% {
			transform: scale(0.8);
			opacity: 0.13;
		}

		50% {
			transform: scale(1);
			opacity: 0.1;
		}

		75% {
			transform: scale(1.2);
			opacity: 0.07;
		}

		100% {
			transform: scale(1.4);
			opacity: 0.01;
		}
	}
    </style>

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
实现类似水波纹动画效果,可以通过以下步骤: 1. 首先,在 HTML 中添加一个带有图片的 div,并设置其 position 为 relative。 2. 然后,在 CSS 中添加以下样式: ```css div { position: relative; overflow: hidden; } div::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: radial-gradient(circle, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 80%); transform: scale(10); opacity: 0; animation: ripple 1s linear infinite; } @keyframes ripple { to { opacity: 1; transform: scale(20); } } ``` 3. 解释一下上面的 CSS: div::after 用来创建一个伪元素,覆盖在图片上面,实现水波纹效果。 background-image 设置为径向渐变,从白色到透明,实现水波纹扩散效果。 transform 设置为 scale(10),表示初始状态水波纹半径为图片的 1/10。 opacity 设置为 0,表示初始状态水波纹不可见。 animation 定义了一个名为 ripple 的动画实现水波纹扩散和逐渐显现的效果。 4. 最后,通过调整 animation 的 duration 和 timing-function 属性,可以调整动画的速度和缓动效果。 完整的代码如下: ```html <div> <img src="your-image.jpg" alt=""> </div> ``` ```css div { position: relative; overflow: hidden; } div::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: radial-gradient(circle, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 80%); transform: scale(10); opacity: 0; animation: ripple 1s linear infinite; } @keyframes ripple { to { opacity: 1; transform: scale(20); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mickey_于浩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值