CSS3 微调器、预加载器

标签 css css-animations css-transforms css-shapes

我想用 CSS3 构建一个动画微调器。 它应该像这样:

CSS spinner state 1 CSS spinner state 2 CSS spinner state 3 CSS spinner state 4

在最后一个状态之后,它应该像第一个状态一样再次开始。

我设法使用这里解释的技术创建了圆圈:stackoverflow question

现在,如何在所描述的状态之间为微调器设置动画?我不知道如何为 clip-rect 属性设置动画。我还猜想如果使用 clip-poly(可能是三 Angular 形)它会表现得更好,但我也不能为它制作动画。

最佳答案

CSS3 微调器

此 CSS 预加载器使用关键帧动画和 transform-rotate CSS3 属性制作圆圈和填充颜色。

这个微调器是响应式的。

.sp1 {
  margin: 50px auto;
  position: relative;
  width: 30%;
  padding-bottom: 30%;
  overflow: hidden;
  background-color: #557733;
  border-radius: 50%;
  z-index: 1;
}

.sp:before,
.sp:after {
  content: '';
  position: absolute;
  height: 100%;
  width: 50%;
  background-color: #99FF33;
}

.sp1:after {
  width: 80%;
  height: 80%;
  margin: 10%;
  border-radius: 50%;
  background-color: #fff;
  z-index: 6;
}

.sp1:before {
  background-color: inherit;
  z-index: 5;
}

.sp2:before {
  z-index: 4;
  -webkit-animation: spin1 3s linear infinite;
          animation: spin1 3s linear infinite;
  -webkit-transform-origin: 100% 50%;
          transform-origin: 100% 50%;
}

.sp2:after {
  opacity: 0;
  right: 0;
  z-index: 6;
  -webkit-animation: spin2 3s linear infinite;
          animation: spin2 3s linear infinite;
  -webkit-transform-origin: 0 50%;
          transform-origin: 0 50%;
}

@-webkit-keyframes spin1 {
  0%         { -webkit-transform: rotate(0deg); }
  50%, 100%  { -webkit-transform: rotate(180deg); }
   
}

@keyframes spin1 {
  0%         { transform: rotate(0deg); }
  50%, 100%  { transform: rotate(180deg); }
}

@-webkit-keyframes spin2 {
  0% { -webkit-transform: rotate(0deg); opacity: 0; }
  49.99% { opacity: 0; }
  50% { -webkit-transform: rotate(0deg);  opacity: 1; }
  100% { -webkit-transform: rotate(180deg); opacity: 1;
  }
}

@keyframes spin2 {
  0% { transform: rotate(0deg); opacity: 0; }
  49.99% { opacity: 0; }
  50% { transform: rotate(0deg); opacity: 1; }
  100% { transform: rotate(180deg); opacity: 1; }
}
<div class="sp sp1">
  <div class="sp sp2"></div>
</div>

Fiddle demo

关于CSS3 微调器、预加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24484727/

相关文章:

javascript - svg元素的自下而上的CSS动画

css - 反向无限淡入淡出线

javascript - CSS:使最后一个菜单项边框倾斜

html - 伪元素在 CSS 变换上从父元素下方移动到父元素上方

css - 在电子邮件模板中使用绝对/相对位置

css - 围绕 X 轴上的圆进行 3D 变换

javascript - 不能在 CSS 动画上使用延迟

css - 绕垂直轴旋转 45 度元素

javascript - 如何在 fullpage.js 中应用固定背景

html - 加载相对于网站位置的背景图像