实例:水波纹按钮效果
技术栈:HTML+CSS
效果:
源码:
【html】
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<title>水波纹效果按钮</title>
<link rel="stylesheet" href="../css/56.css">
</head>
<body>
<div class="btn-box">
<div class="btn">
<span>点赞</span>
<div class="wave"></div>
</div>
<div class="btn">
<span>关注</span>
<div class="wave"></div>
</div>
<div class="btn">
<span>收藏</span>
<div class="wave"></div>
</div>
<div class="btn">
<span>转发</span>
<div class="wave"></div>
</div>
</div>
</body>
</html>
【css】
*{
/* 初始化 */
margin: 0;
padding: 0;
}
body{
/* 100%窗口高度 */
height: 100vh;
/* 弹性布局 居中 */
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(200deg,#e7f0fd,#accbee);
}
.btn-box{
width: 500px;
/* 弹性布局 */
display: flex;
/* 横向排列 */
flex-direction: row;
/* 允许换行 */
flex-wrap: wrap;
/* 平均分配宽度给每一个子元素 */
justify-content: space-around;
}
.btn{
/* 相对定位 */
position: relative;
width: 200px;
height: 60px;
line-height: 60px;
text-align: center;
margin: 20px 0;
font-size: 18px;
/* 字间距 */
letter-spacing: 4px;
color: #00aeff;
border: 2px solid #00aeff;
cursor: pointer;
/* 溢出隐藏 */
overflow: hidden;
}
.btn span{
position: relative;
z-index: 1;
/* 动画过渡 */
transition: 1s;
}
.btn .wave{
/* 绝对定位 */
position: absolute;
/* 计算top */
top: calc(100% + 22px);
left: 0;
width: 100%;
height: 100%;
background-color: #00aeff;
transition: 1s;
}
.btn .wave::before{
content: "";
position: absolute;
top: -22px;
left: 0;
width: 100%;
height: 22px;
background-image: url("../images/wave.png");
/* 执行动画:动画名 时长 线性的 无限次播放 */
animation: animate 0.5s linear infinite;
}
.btn:hover .wave{
top: 0;
}
.btn:hover span{
color: #fff;
}
/* 定义动画 */
@keyframes animate {
0%{
/* 改变背景X轴定位和Y轴定位 */
background-position-x: 0;
background-position-y: -22px;
}
100%{
background-position-x: 118px;
background-position-y: -22px;
}
}