css animation on “content:” doesn't work on Safari and Firefox

前端 未结 5 708
情深已故
情深已故 2020-12-03 23:43

I have an animation set on :before that works fine on Chrome but it doesn\'t work on Safari (IOS9 iPhone or 9 - El Capitan) neither on Firefox.

5条回答
  •  庸人自扰
    2020-12-03 23:57

    in safari and firefox the code isn't animation, instead you'll have to write -moz-animation and also -webkit-animation, like this code:

    .hey {
      color: white;
    }
    .hey:before {
      content: 'Hey \a there';
      white-space: pre;
      position: absolute;
      color: red;
      animation: heyThere 2250ms steps(11);
      -moz-animation: heyThere 2250ms steps(11); /* for firefox */
      -webkit-animation: heyThere 2250ms steps(11); /* for safari, chrome & opera */
    }
    
    @keyframes heyThere {
        0% {content: "";}
        1% {content: "";}
        75% {content: "";}
        77% {content: "H";}
        80% {content: "He";}
        83% {content: "Hey";}
        85% {content: "Hey ";}
        87% {content: "Hey \a t";}
        90% {content: "Hey \a th";}
        93% {content: "Hey \a the";}
        95% {content: "Hey \a ther";}
        97% {content: "Hey \a there";}
        100% {content: "Hey \a there";}
    }
    @-moz-keyframes heyThere { /* animation for firefox */
        0% {content: "";}
        1% {content: "";}
        75% {content: "";}
        77% {content: "H";}
        80% {content: "He";}
        83% {content: "Hey";}
        85% {content: "Hey ";}
        87% {content: "Hey \a t";}
        90% {content: "Hey \a th";}
        93% {content: "Hey \a the";}
        95% {content: "Hey \a ther";}
        97% {content: "Hey \a there";}
        100% {content: "Hey \a there";}
    }
    @-webkit-keyframes heyThere { /* animation for chrome, safari & opera */
        0% {content: "";}
        1% {content: "";}
        75% {content: "";}
        77% {content: "H";}
        80% {content: "He";}
        83% {content: "Hey";}
        85% {content: "Hey ";}
        87% {content: "Hey \a t";}
        90% {content: "Hey \a th";}
        93% {content: "Hey \a the";}
        95% {content: "Hey \a ther";}
        97% {content: "Hey \a there";}
        100% {content: "Hey \a there";}
    }
    

    `

提交回复
热议问题