Sass Keyframes animation mixin generating invalid CSS

后端 未结 2 901
南旧
南旧 2020-12-11 17:19

I have the following keyframes mixin, but it seems to be generated invalid CSS:

@mixin keyframes($animationName)
{
    @-webkit-keyframes $animationName {
           


        
相关标签:
2条回答
  • 2020-12-11 17:52

    Same as above with prefixes:

    @mixin keyframes($animationName) {
      @-webkit-keyframes #{$animationName} {
        $browser: '-webkit-' !global;
        @content;
      }
      @-moz-keyframes #{$animationName} {
        $browser: '-moz-' !global;
        @content;
      }
      @-o-keyframes #{$animationName} {
        $browser: '-o-' !global;
        @content;
      }
      @keyframes #{$animationName} {
        $browser: '' !global;
        @content;
      }
    } $browser: null;
    

    Full details here.

    Or just use Autoprefixer instead.

    0 讨论(0)
  • 2020-12-11 17:55

    You're required to use string interpolation on variables for keyframes names. Your keyframes mixin needs to be written like this:

    @mixin keyframes($animationName)
    {
        @-webkit-keyframes #{$animationName} {
            @content;
        }
        @-moz-keyframes #{$animationName}  {
            @content;
        }
        @-o-keyframes #{$animationName} {
            @content;
        }
        @keyframes #{$animationName} {
            @content;
        }
    }
    

    Note that the keyframes mixin that comes with Compass does this.

    There is an issue on GitHub that indicates that interpolation was not required in certain versions of Sass (possibly limited to 3.3.x). However, the authors of Sass considered it to be a bug:

    The previous behavior was a bug. Variables should never have been allowed uninterpolated in any directives.

    0 讨论(0)
提交回复
热议问题