之前发过一个边框闪烁的,其实原理相同。由于最近做项目需要这个效果,重新整了一个,希望能帮助大家使用。直接上代码。
<!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>ceshi</title>
<style>
span {
position: relative;
display: flex;
height: 118px;
width: 118px;
z-index: 1;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
background: #fcc79d;
border-radius: 50%;
justify-content: center;
align-items: center;
}
span::after {
z-index: -1;
border-radius: 50%;
background-color: #fcc79d;
content: "";
bottom: 0;
left: 0;
right: 0;
top: 0;
position: absolute;
-webkit-animation: pulsate 1.5s ease infinite;
animation: pulsate 1.5s ease infinite;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
@-webkit-keyframes pulsate {
0% {
transform: scale(1);
opacity: 1
}
50% {
transform: scale(1.2);
opacity: .5
}
to {
transform: scale(1);
opacity: 1
}
}
@keyframes pulsate {
0% {
transform: scale(1);
opacity: 1
}
50% {
transform: scale(1.2);
opacity: .5
}
to {
transform: scale(1);
opacity: 1
}
}
</style>
</head>
<body>
<span>haha</span>
</body>
</html>
比起之前边框闪烁的,代码更精简。