Sass and Keyframes



我正试图使用css关键帧创建一个旋转圆,但我很难在Sass中实现这一点。

这是我的html:

<div class="content">
    <h1 class="h1">Playing around with keyframes</h1>
    <div class="circle"></div>
</div>

这是Sass:

.content{
        display:block;
        position: relative;
        box-sizing:border-box;
        .circle{
            width: 220px;
            height: 220px;
            border-radius: 50%;
            padding: 10px;
            border-top: 2px solid $pink;
            border-right: 2px solid $pink;
            border-bottom: 2px solid $pink;
            border-left: 2px solid #fff;
            -webkit-animation:spin 4s linear infinite;
            -moz-animation:spin 4s linear infinite;
            animation:spin 4s linear infinite;
        }
        @-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
        @-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
        @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
    }

我正在使用Prepros编译我的Sass,输出如下(注意关键帧内的类):

@-moz-keyframes spin {
  .lesson-page .content 100%  {
    -moz-transform: rotate(360deg);
  }
}
@-webkit-keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
  }
}
@keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

这似乎是Sass 3.3特有的。@keyframes构造没有正确地冒泡到顶部。如果无法升级到3.4,只需停止嵌套关键帧即可。

.content{
    display:block;
    position: relative;
    box-sizing:border-box;
    .circle{
        width: 220px;
        height: 220px;
        border-radius: 50%;
        padding: 10px;
        border-top: 2px solid $pink;
        border-right: 2px solid $pink;
        border-bottom: 2px solid $pink;
        border-left: 2px solid #fff;
        -webkit-animation:spin 4s linear infinite;
        -moz-animation:spin 4s linear infinite;
        animation:spin 4s linear infinite;
    }
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }

相关:如何使Sass mixin在基本级别上声明一个非嵌套选择器?

最新更新