css - 仅使用 HTML 和 SCSS(或 CSS)复制 SVG stroke-dasharray

标签 css svg sass frontend

我正在尝试创建类似于此示例的经典圆形加载器 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>

来源:https://loading.io/css/

关于css - 仅使用 HTML 和 SCSS(或 CSS)复制 SVG stroke-dasharray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55760731/

相关文章:

css - 为什么最小高度会将 div 推到底部?

html - SVG 蒙版无法在 Chrome 中调整大小

css - 如何使用 Angular 2 在 Ionic 2 中使用新的字体样式(如 AR Destiny)?

css - 如何用 React 覆盖默认的 MaterialUI 样式?

html - 在视口(viewport)高度之上具有未知高度的中心 div

javascript - SVG 过滤器动画问题

css - 将伪元素选择器作为 SASS 中的变量传递

css - 是否存在多个子选择器?

javascript - 在鼠标悬停时展开/折叠 float div 而不会掉到下一行

performance - Canvas 与 SVG 动画(效果 [过滤器] 和性能)