wx公众号:XQ前端
1. 效果预览
2. 源码
我们通过伪元素和渐变实现以上效果
// 边框动画
@mixin border-animate() {
position: relative;
border-color: #24AFFF;
color: #24AFFF;
opacity: 0.8;
background: #3c3d45;
&:before, &:after {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
border-style: solid;
border-width: 2px;
border-image-source: linear-gradient(-45deg, #0d76ec 0%, #00f0ff 100%);
border-image-slice: 1;
}
&:before {
top: 0;
left: 0;
opacify: 0;
border-bottom: none;
border-left: none;
transition: width 0.1s ease-out 0.3s, height 0.1s ease-out 0.2s, opacity 0.2s ease-out 0.2s;
}
&:after {
bottom: 0;
right: 0;
opacity: 0;
border-right: none;
border-top: none;
transition: width 0.1s ease-out 0.1s,height 0.1s ease-out 0s, opacity 0.4s;
}
&:hover {
&:before, &:after{
opacity: 1;
width: 100%;
height: 100%;
}
&:before {
opacity: 1;
width: 100%;
height: 100%;
transition: width 0.1s ease-in 0s,height 0.1s ease-in 0.1s, opacity 0.4s;
}
&:after {
opacity: 1;
width: 100%;
height: 100%;
transition: width 0.1s ease-in 0.2s,height 0.1s ease-in 0.3s, opacity 0.4s;
}
}
}
.q-btn-wrap{
background: #3c3d45;
padding: 33px;
width: 110px;
.q-button{
cursor: pointer;
border: none;
display: inline-block;
width: 100px;
height: 30px;
color: #ff4b4b;
@include border-animate()
}
}
欢迎大家关注 wx公众号:XQ前端
每天分享一点前端小知识