我正在尝试创建类似于此示例的经典圆形加载器 https://dribbble.com/shots/1918018-Circle-Loading-Animation
所以,我知道可以将 SVG 与 stroke-dasharray 一起使用,并且肯定这将是简单的方法。 顺便说一句,我想问一下是否有另一种方法可以仅使用 SCSS(或 CSS)来做到这一点。
我的目标是复制那种加载器,而不向 HTML 文件添加任何 SVG。
谢谢!
最佳答案
如果您同意最小 stroke-dashoffset
为圆周长的 25%,您可以按如下方式进行。
基本上您有四个正方形子元素。每个都有一个圆形边框,覆盖正方形的一侧(即圆周的 25%)。这些子元素全部重叠。然后你用稍微不同的动画开始时间旋转每个 child 。
.lds-ring {
display: inline-block;
position: relative;
width: 64px;
height: 64px;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 51px;
height: 51px;
margin: 6px;
border: 6px solid #fff;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #fff transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
body {
background-color: black;
}
<div class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
关于css - 仅使用 HTML 和 SCSS(或 CSS)复制 SVG stroke-dasharray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55760731/