编写html代码
使用css3动画做一个会发光的按钮特效特别简单,主要用到了css3的@keyframes动画属性,按钮效果如下:
html代码部分如下:
<div class="content">
<div class="btn">点击</div>
<div class="btn_animation"></div>
</div>
编写css代码
css代码如下:
.content{
position: relative;
}
.btn{
width: 200px;
height: 200px;
background-color: #2979ff;
border-radius: 50%;
position: absolute;
text-align: center;
line-height: 200px;
color: #fff;
font-size: 2em;
z-index: 999;
}
.btn:active{
background-color: #ecf5ff;
}
.btn_animation{
width: 200px;
height: 200px;
border-radius: 50%;
background-color: #a0cfff;
animation: scale 1.5s infinite cubic-bezier(0,0,0.49,1.02);
}
@keyframes scale {
0%{
transform: scale(1);
}
50%, 75%{
transform: scale(1.2);
}
78%, 100%{
opacity: 0;
}
}
整体代码结构如下:
<!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>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100vw;
height: 100vh;
background-color: #f8f8f8;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.content{
position: relative;
}
.btn{
width: 200px;
height: 200px;
background-color: #2979ff;
border-radius: 50%;
position: absolute;
text-align: center;
line-height: 200px;
color: #fff;
font-size: 2em;
z-index: 999;
}
.btn:active{
background-color: #ecf5ff;
}
.btn_animation{
width: 200px;
height: 200px;
border-radius: 50%;
background-color: #a0cfff;
animation: scale 1.5s infinite cubic-bezier(0,0,0.49,1.02);
}
@keyframes scale {
0%{
transform: scale(1);
}
50%, 75%{
transform: scale(1.2);
}
78%, 100%{
opacity: 0;
}
}
</style>
</head>
<body>
<div class="content">
<div class="btn">点击</div>
<div class="btn_animation"></div>
</div>
</body>
</html>