"content:"上的 css 动画在 Safari 和 Firefox 上不起作用

标签 css animation css-selectors css-animations

我在 :before 上设置了一个动画,它在 Chrome 上运行良好,但在 Safari(IOS9 iPhone 或 9 - El Capitan)上无法运行,在 Firefox 上也无法运行。

.hey {
  color: white;
}
.hey:before {
  content: 'Hey \a there';
  white-space: pre;
  position: absolute;
  color: red;
 -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";}
}
<div class="hey">Hey there</div>

最佳答案

我也翻遍了全网也没有发现,根据下面的引用我们只能用JavaScript实现。

In my own testing animating content has only worked in stable desktop Chrome (v46 at time of writing). No support anywhere else. No Safari on desktop or iOS. No Firefox. No IE. Each of these browsers will ignore the animation, showing only the original content in the pseudo element.

Reference

关于 "content:"上的 css 动画在 Safari 和 Firefox 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57524576/

相关文章:

css - 仅将 css 应用于第一个 child 并取消继承

screen-scraping - Selenium RC CSS 定位器可能比 XPath 慢的原因是什么?

html - 如何在不创建 slider 并继续此页面的情况下将图像拉伸(stretch)到整页高度?

php - 电子邮件中没有数据

css - 为什么内容跨越 :after {content: ' ' } is put inside span and not after?

jQuery Mobile - 具有多个内部页面的面板

javascript - 在 DOM 中添加新元素后保留元素屏幕位置

javascript - 在 D3.js 中子级转换结束后删除父级

Android ViewPropertyAnimator 不会同时缩放

CSS :target another element