The problem I am running into occurs when trying to animate a web font. Specifically, if the HTML element has a class that defines the font-family
and other needed CSS attributes on the :before
element as opposed to the element itself, the pseudo content will not get animated.
Here is some sample CSS:
@font-face {
font-family: 'FontAwesome';
src: /** src urls here... **/
}
.fa-before:before,
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-refresh:before {
content: "\f021";
}
.spinning-loader {
-webkit-animation: fa-spin 2s infinite linear;
animation: fa-spin 2s infinite linear;
}
@-webkit-keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
@keyframes fa-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(359deg);
transform: rotate(359deg);
}
}
Now the key part is my fa
and fa-before:before
selectors.
If I use the fa-before
class, that works fine to set the correct font-family
of my :before
content. Additionally, plain fa
also works fine for the :before
content (and I think any other content too).
The problem is, if an element has fa-before
, it doesn't animate (at least, not all browsers animate it).
<!-- This doesn't always animate -->
<i class="fa-before icon-refresh spinning-loader"></i>
<!-- This DOES always animate -->
<i class="fa icon-refresh spinning-loader"></i>
When it works:
When it doesn't work:
Here is a JSFiddle so you can test in your own browser: https://jsfiddle.net/b3gojahs/1/
Here are all the browsers I've been able to test:
- Works in:
- Mac OS X 10.10.5
- Chrome 47.0.2526.111
- Windows 10.0.10240
- IE 11.0.10240.16644
- Edge 10.10240.16384.0
- Mac OS X 10.10.5
- Doesn't work in:
- Mac OS X 10.10.5
- Chrome Canary 50.0.2639.0 (!!)
- Safari 9.0.3 (10601.4.4)
- Firefox 44.0
- Windows 10.0.10240
- Chrome 48.0.2564.97
- Firefox 44.0
- Mac OS X 10.10.5
Anyone know why this is occurring? I can't seem to find any articles on this issue.