How should you prefix transform properties in CSS3 animations?

后端 未结 3 1968
执笔经年
执笔经年 2020-12-04 00:30

I have the following snippet of Sass that works like a charm, but I wonder if I need to prefix my transform properties, and, if so, how? (if not, why not?)

@         


        
3条回答
  •  醉酒成梦
    2020-12-04 01:07

    The short answer is: Don't roll your own. BoltClock already did an excellent job of explaining why your implementation won't be good enough for all scenarios (prefixed properties vs prefixed values).

    The good news is that the fine people at Compass have already solved this problem for you.

    @include keyframes(expand-o-band) {
        0% {
          /* prefixed property */
            @include border-radius(0);
        }
    
        100% {
            @include border-radius(1em);
            /* prefixed value */
            @include background(linear-gradient(to bottom, black, white));
        }
    }
    
    .circle-thing {
        @include animation(expand-o-band 1.5s infinite);
      background: yellow;
        padding: 5em;
        border: 1px solid;
    }
    

    Output:

    @-moz-keyframes expand-o-band {
      0% {
        /* prefixed property */
        -moz-border-radius: 0;
        border-radius: 0;
      }
      100% {
        -moz-border-radius: 1em;
        border-radius: 1em;
        /* prefixed value */
        background: -moz-linear-gradient(top, #000000, #ffffff);
        background: linear-gradient(to bottom, #000000, #ffffff);
      }
    }
    @-webkit-keyframes expand-o-band {
      0% {
        /* prefixed property */
        -webkit-border-radius: 0;
        border-radius: 0;
      }
      100% {
        -webkit-border-radius: 1em;
        border-radius: 1em;
        /* prefixed value */
        background: -webkit-linear-gradient(top, #000000, #ffffff);
        background: linear-gradient(to bottom, #000000, #ffffff);
      }
    }
    @keyframes expand-o-band {
      0% {
        /* prefixed property */
        -moz-border-radius: 0;
        -webkit-border-radius: 0;
        border-radius: 0;
      }
      100% {
        -moz-border-radius: 1em;
        -webkit-border-radius: 1em;
        border-radius: 1em;
        /* prefixed value */
        background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #000000), color-stop(100%, #ffffff));
        background: -moz-linear-gradient(top, #000000, #ffffff);
        background: -webkit-linear-gradient(top, #000000, #ffffff);
        background: linear-gradient(to bottom, #000000, #ffffff);
      }
    }
    .circle-thing {
      -moz-animation: expand-o-band 1.5s infinite;
      -webkit-animation: expand-o-band 1.5s infinite;
      animation: expand-o-band 1.5s infinite;
      background: yellow;
      padding: 5em;
      border: 1px solid;
    }
    

    http://sassmeister.com/gist/2413d0894bf609e80b5d

    By default, Compass will maximize browser compatibility (and is fully configurable). All of their mixins that emit prefixes are compatible with their keyframes mixin. I can't even paste the relevant code to recreate the magic that goes into this because there is so much of it.

提交回复
热议问题