I have several animations on my site that I just realized do not even show up in Firefox or Internet Explorer. I have the background-image
within the keyframes. I do this because I have different images in different percentages with the animation.
Why doesn't the background-image
display within the keyframes in Firefox and Internet Explorer and is there a way to make this work?
As per the specs,
background-image
is not an animatable or a transitionable property. But it does not seem to say anything about what or how the handling should be when it is used as part of transition or animation. Because of this, each browser seem to be handling it differently. While Chrome (Webkit) is displaying the background image, Firefox and IE seem to do nothing.The below quote found in an article at oli.jp provides some interesting information:
On the face of it, it looks like Firefox and IE are handling it correctly while Chrome is not. But, it is not so simple. Firefox seems to contradict itself when it comes to how it handles transition on background image as opposed to animation. While transitioning
background-image
, it shows up the second image immediately (hover
the firstdiv
in the snippet) whereas while animating, the second image doesn't get displayed at all (hover
the seconddiv
in the snippet).So, conclusion is that it is better to not set
background-image
inside keyframes. Instead, we have to usebackground-position
oropacity
like specified @ oli.jp.If you have multiple images that should be shown at different percentages within the keyframe then it would be a better idea to add all those images on the element at start and animate their position like in the below snippet. This works the same way in Firefox, Chrome and IE.
Or, like in the below snippet. Basically each image is the same size as the container as
background-size
is set as100% 100%
but only one image is shown at any given time because of them being the same size as container. Between0%
to50%
the first image is shown because it is at0px,0px
(left-top) whereas the second image is at100px,0px
(outside the right border). At50.1%
, the first image is at-100px,0px
(outside left border) and second image is at0px,0px
and so it is visible.