直播平台开发,Clip-path实现按钮流动边框动画
直播平台开发,Clip-path实现按钮流动边框动画
1.实现步骤
添加div标签
<div>苏苏_icon</div>
div {
position: relative;
width: 220px;
height: 64px;
line-height: 64px;
text-align: center;
color: #fff;
font-size: 20px;
background: #55557f;
cursor: pointer;
border-radius: 10px;
}
为div添加前后伪元素,为了方便区分,设置前后伪元素的边框颜色不同
div::after,
div::before {
content: "";
position: absolute;
width: 240px;
height: 84px;
border: 2px solid #55557f;
border-radius: 10px;
}
div::before{
border: 2px solid orange;
}
修改伪元素的定位位置
div::after,
div::before{
+ left: calc(110px - 120px);
+ top: calc(32px - 42px);
}
2.实现代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>clip-path实现按钮流动边框</title>
</head>
<link rel="stylesheet" href="../common.css" />
<style>
div {
position: relative;
width: 220px;
height: 64px;
line-height: 64px;
text-align: center;
color: #fff;
font-size: 20px;
background: #55557f;
cursor: pointer;
border-radius: 10px;
/* 添加过渡效果 */
transition: all 0.5s;
}
div::after,
div::before {
content: "";
position: absolute;
border: 2px solid #55557f;
width: 240px;
height: 84px;
border-radius: 10px;
/* 简写为 */
inset: -10px;
/* 添加动画 */
animation: pathRotate 3s infinite linear;
}
@keyframes pathRotate {
0%,
100% {
clip-path: inset(0 0 98% 0);
}
25% {
clip-path: inset(0 98% 0 0);
}
50% {
clip-path: inset(98% 0 0 0);
}
75% {
clip-path: inset(0 0 0 98%);
}
}
div::after {
animation-delay: -1.5s;
}
div:hover {
filter: brightness(1.5);
}
</style>
<body>
<div>苏苏_icon</div>
</body>
</html>
以上就是直播平台开发,Clip-path实现按钮流动边框动画, 更多内容欢迎关注之后的文章