【问题标题】:Snake loader css animation keyframes doesn't workSnake loader css动画关键帧不起作用
【发布时间】:2015-04-29 00:16:56
【问题描述】:

我正在尝试使用关键帧动画制作带有 css 的蛇形加载器微调器,但我不知道它不起作用 有人可以帮忙吗? 这里的小提琴: https://jsfiddle.net/fs6kafsn/

@keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}

.spinner {
     display: block;
     margin: 50px;
     height: 28px;
     width: 28px;
     animation: rotate 0.8s infinitelinear!important;
     -webkit-animation: rotate 0.8s infinitelinear!important;
     border: 8px solid red;
     border-right-color: transparent;
     border-radius: 50%;
     position:relative;
}

提前致谢

【问题讨论】:

  • 你忘了保存小提琴 :) 和它的空白。
  • 你太快了,我只是在编辑......

标签: css animation spinner keyframe


【解决方案1】:

您还需要为关键帧添加前缀。

fiddle demo

@-webkit-keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}
@keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}

这也需要以 -moz- 为前缀,以便与 firefox 兼容。

注意

无前缀版本应始终放在有前缀版本之后。

完整演示

.spinner {
    display: block;
    margin: 50px;
    height: 28px;
    width: 28px;    
    -webkit-animation: rotate 0.8s infinite linear !important;
    -moz-animation: rotate 0.8s infinite linear !important;
    animation: rotate 0.8s infinite linear !important;
    border: 8px solid red;
    border-right-color: transparent;
    border-radius: 50%;
    position:relative;
}
@-webkit-keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}
@-moz-keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}
@keyframes rotate {
    0%    { transform: rotate(0deg); }
    100%  { transform: rotate(360deg); }
}
   <div class="spinner">

        </div>

【讨论】:

    【解决方案2】:

    对于基于 webkit 的浏览器,例如 chrome,您需要 @-webkit-keyframes,对于 Mozilla firefox,您需要 @-moz-keyframes

    @keyframes spin {
        0%    { transform: rotate(0deg); }
        100%  { transform: rotate(360deg); }
    }
    
    @-webkit-keyframes spin {
        0%    { transform: rotate(0deg); }
        100%  { transform: rotate(360deg); }
    }
    
    
    @-moz-keyframes spin {
        0%    { transform: rotate(0deg); }
        100%  { transform: rotate(360deg); }
    }
    
    .spinner {
        display: block;
        margin: 50px;
        height: 28px;
        width: 28px;
        animation: spin 0.8s infinite linear!important;
        -webkit-animation: spin 0.8s infinite linear!important;
        border: 8px solid red;
        border-right-color: transparent;
        border-radius: 50%;
        position:relative;
    }
       <div class="spinner">
    
            </div>

    【讨论】:

      【解决方案3】:

      我改变了你的小提琴。这是工作动画:fiddle:


      代码:

      @-moz-keyframes myanimation /* Firefox */
      {
          0%   {transform: rotate(0deg);}
          100%   {transform: rotate(360deg);}
      }
      
      @-webkit-keyframes myanimation /* Safari and Chrome */
      {
          0%   {transform: rotate(0deg);}
          100%   {transform: rotate(360deg);}
      }
      
      .spinner {
          display: block;
          margin: 50px;
          height: 28px;
          width: 28px;
          animation:myfirst 5s;
          -moz-animation:myanimation 0.8s infinite linear; /* Firefox */
          -webkit-animation:myanimation 0.8s infinite linear; /* Safari and Chrome */
          border: 8px solid red;
          border-right-color: transparent;
          border-radius: 50%;
          position:relative;
      }
      

      【讨论】:

      • 这并没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
      • @JanSpurny 这几乎回答了这个问题。 Petroff 应该添加了代码的一些关键部分,否则这是非常有效的。
      • @JanSpurny 小提琴完全按照他的意愿行事。为什么你认为这不是答案?
      • 我相信答案应该在stackoverflow上在答案本身中。而且我也相信在答案中提供有用的解释,而不仅仅是一个链接,即使这个链接是有帮助的。您的回答只是参考您所做的编辑。这可能就是为什么 jbutler483 的回答被接受而你的回答不被接受的原因。但是,我认为您部分正确,因为我可能选择了错误的评论。
      • 答案应该不仅仅是链接,因为只有链接的答案可能会被删除。在 Meta Stack Exchange 上查看这个问题:Your answer is in another castle: when is an answer not an answer?
      猜你喜欢
      • 1970-01-01
      • 2016-03-26
      • 2021-10-20
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多