我创建了一个带有渐变边框的框,我想为该渐变设置动画,使其进行 360 度旋转。
使用我目前正在处理的代码,不是渐变背景本身在旋转,而是实际的盒子在旋转。有趣,但不是我想要的结果。哈哈 关于如何解决这个问题有什么建议吗?这是我当前的代码:
.gradient-border {
position: relative;
width: 500px;
height: 500px;
}
.gradient-border::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 25px;
border: 7px solid transparent;
background: linear-gradient(45deg, #4158D0, #C850C0, #FFCC70) border-box;
-webkit-mask:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: destination-out;
mask-composite: exclude;
animation: rotate-gradient linear 5s infinite;
}
@keyframes rotate-gradient {
100% {
-webkit-transform: rotate(360deg);
transform:rotate(360deg);
}
}
<div class="gradient-border"></div>
感谢您的帮助!
也许你可以改为动画背景:
@keyframes rotate-gradient {
100% {
/*-webkit-transform: rotate(360deg);
transform: rotate(360deg);*/
background: linear-gradient(85deg, #4158D0, #C850C0, #FFCC70) border-box;
}
}
也许会降低到 5 秒到 3 秒。
.gradient-border::before {
animation: rotate-gradient linear 3s infinite;
}
}
试试这个:
.gradient-border {
position: relative;
height: 500px;
width: 500px;
overflow: hidden;
padding: 7px;
background: transparent;
}
.gradient-border::before {
content: "";
position: absolute;
background: linear-gradient(45deg, #4158D0, #C850C0, #FFCC70);
height: 1000px;
width: 1000px;
top: -50%;
left: -50%;
bottom: 50%;
right: 50%;
animation: rotate-gradient linear 2.5s infinite;
}
.gradient-border::after {
content: '';
position: absolute;
background: #fff;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 15px;
}
@keyframes rotate-gradient {
0% {
-webkit-transform: rotate(0deg);
transform:rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform:rotate(360deg);
}
}
<body>
<div class="gradient-border"></div>
</body>