"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/40027799/

相关文章:

javascript - 如果使用 Javascript 设置为 div 背景,图像 URL 不起作用

html - 从 foundation.css 中删除 .has-dropdown 箭头

html - 如何将文字放在封面图片下方?

ios - Swift Zoom Transition Animation 仅在第二次不起作用

javascript - 完全旋转和随机化所有 DOM 元素

css - 在 1 行中将 css 应用到我的表的头部和主体

python - 识别表格行和表格数据 - CSS Selector Python

html - 为什么不溢出 : hidden working?

CSS 动画播放不流畅

html - 添加了第二个 css 下拉列表,它不会排队