It seems that the CSS attributes set by animation-fill-mode: forwards cannot be overwritten on the same element.
Or: add parent shell around
One solution is to set a wrapper around the element with animation-fill-mode: forwards . Then, to rewrite the redirected attributes, you only need to update the parent.
<div id="parent"> <div id="my-text">I just faded in!</div> </div>
Then overwrite the opacity for the parent only:
$('#parent').css('opacity', 0);
I implemented the changes in your fiddle here: http://jsfiddle.net/x3mbkbwL/3/
Or: a wrapper nest inside
If you prefer, you can add another child element instead:
<div id="my-text"> <span id="wrapper">I just faded in!</span> </div>
Then "rewrite" opacity only on the nested shell:
$('#wrapper').css('opacity', 0);
Both approaches work best if the redirected opacity is set to 1 . If it is sent to 0 , then it obviously will not work, because the element is already hidden.
source share