代码之家  ›  专栏  ›  技术社区  ›  Savage

CSS微调器不旋转

css
  •  -1
  • Savage  · 技术社区  · 8 年前

    我正在使用带有以下标记的CSS微调器:

    .spinner {
      height: 25px;
      width: 25px;
      margin: 0 auto 0 auto;
      position: relative;
      -webkit-animation: rotation .6s infinite linear;
      -moz-animation: rotation .6s infinite linear;
      -o-animation: rotation .6s infinite linear;
      animation: rotation .6s infinite linear;
      border-left: 4px solid #fff;
      border-right: 4px solid #fff;
      border-bottom: 4px solid #fff;
      border-top: 4px solid #0F8254;
      border-radius: 100%;
      display: inline-block;
      vertical-align: middle;
    }
    <span class="spinner"></span>

    它不会旋转,无论我把它放在页面中的什么地方,在firefox/chrome/ie上,如果我在firefox中检查,就不会有被覆盖的属性。

    3 回复  |  直到 8 年前
        1
  •  3
  •   Vincent Smedinga    8 年前

    你指的是一个叫做 rotation 但似乎还没有定义。像这样添加:

    .spinner {
      height: 25px;
      width: 25px;
      margin: 0 auto 0 auto;
      position: relative;
      -webkit-animation: rotation .6s infinite linear;
      -moz-animation: rotation .6s infinite linear;
      -o-animation: rotation .6s infinite linear;
      animation: rotation .6s infinite linear;
      border-left: 4px solid #fff;
      border-right: 4px solid #fff;
      border-bottom: 4px solid #fff;
      border-top: 4px solid #0F8254;
      border-radius: 100%;
      display: inline-block;
      vertical-align: middle;
    }
    
    /* TODO Add vendor prefixes if you need them */
    @keyframes rotation { 
        from { 
            transform: rotate(0deg); 
        } to { 
            transform: rotate(360deg); 
        }
    }
    <span class="spinner"></span>
        2
  •  3
  •   Dale    8 年前

    看起来你没有定义动画 rotation 在任何地方

    添加

       @keyframes rotation { 
        from { 
            transform: rotate(0deg); 
        } to { 
            transform: rotate(360deg); 
        }
    }
    

    在你的CSS中,它会起作用。

    .spinner {
      height: 25px;
      width: 25px;
      margin: 0 auto 0 auto;
      position: relative;
      -webkit-animation: rotation .6s infinite linear;
      -moz-animation: rotation .6s infinite linear;
      -o-animation: rotation .6s infinite linear;
      animation: rotation .6s infinite linear;
      border-left: 4px solid #fff;
      border-right: 4px solid #fff;
      border-bottom: 4px solid #fff;
      border-top: 4px solid #0F8254;
      border-radius: 100%;
      display: inline-block;
      vertical-align: middle;
      
    
        
    }
    
       @keyframes rotation { 
            from { 
                transform: rotate(0deg); 
            } to { 
                transform: rotate(360deg); 
            }
        }
    <span class="spinner"></span>
        3
  •  0
  •   Savage    8 年前

    好的,我找到了丢失的零件,谢谢您的反馈:

    @-webkit-keyframes rotation {
      from {
        -webkit-transform: rotate(0deg);
      }
      to {
        -webkit-transform: rotate(359deg);
      }
    }
    
    @-moz-keyframes rotation {
      from {
        -moz-transform: rotate(0deg);
      }
      to {
        -moz-transform: rotate(359deg);
      }
    }
    
    @-o-keyframes rotation {
      from {
        -o-transform: rotate(0deg);
      }
      to {
        -o-transform: rotate(359deg);
      }
    }
    
    @keyframes rotation {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(359deg);
      }
    }