实现水波纹点击效果的方法是使用CSS伪元素和CSS3动画。具体步骤如下:
在点击的元素中添加一个伪元素,用于实现水波纹的效果。
使用CSS3动画来控制水波纹的扩散过程,可以使用@keyframes规则来定义动画。
通过CSS的transform属性来实现水波纹的放大效果。
以下是具体的实现代码:
/* 定义点击的元素 */
.btn {
display: inline-block;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
position: relative;
}
/* 定义伪元素 */
.btn::before {
content: "";
display: block;
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
background-color: rgba(255, 255, 255, 0.3);
border-radius: 50%;
opacity: 1;
transform: translate(-50%, -50%);
}
/* 定义动画 */
@keyframes ripple {
0% {
width: 0;
height: 0;
opacity: 0.5;
}
100% {
width: 300px;
height: 300px;
opacity: 0;
}
}
/* 点击时触发动画 */
.btn:active::before {
animation: ripple 0.8s linear;
}
关键词: