Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:59:06+00:00 2026-06-11T20:59:06+00:00

Preface Let’s pretend that a div is animated from opacity:0; to opacity:1; and i

  • 0

Preface

Let’s pretend that a div is animated from opacity:0; to opacity:1; and i want to keep opacity:1; after the animation ends.

That’s what animation-fill-mode:forwards; does.

@keyframes myAnimation {
    from { opacity:0; }
    to { opacity:1; }
}
div {
    opacity:0;
    animation-name:myAnimation;
    animation-delay:1s;
    animation-duration:2s;
    animation-fill-mode:forwards;
}​
<div>just a test</div>​

Run it on jsFiddle

  • Note 1: i didn’t include the vendor prefixes here to simplify
  • Note 2: that’s just an example, please don’t reply with “just use jQuery fadeIn function” etc.

Some things to know

In this answer i read that animation-fill-mode is supported by Chrome 16+, Safari 4+, Firefox 5+.

But animation alone is supported by Chrome 1+ and Opera too. So a general test with Modernizr may return positive even if fill-mode is not supported.

To target animation-fill-mode i added a new test on Modernizr:

Modernizr.addTest('animation-fill-mode',function(){
    return Modernizr.testAllProps('animationFillMode');
});

Now i’ve a .no-animation-fill-mode class for CSS and Modernizr.animationFillMode for JavaScript.

I also read from CSS3 animations specs that:

an animation specified in the document style sheet will begin at the
document load


Finally, the question(s)

Is it ok to run a simple jQuery function at the exact number of seconds the animation ends

$(document).ready(function(){
    if(!Modernizr.animation){
        $('div').delay(1000).fadeIn(2000);
    }else if(!Modernizr.animationFillMode){
        $('div').delay(3000).show();
    }
});

And in CSS:

.no-animation-fill-mode div {
    animation-iteration-count:1;
}
/* or just animation:myAnimation 2s 1s 1; for everyone */

Or is there any known polyfill specific for animation-fill-mode ?


Also, what happens if i use the shorthand syntax

animation:myAnimation 2s 1s forwards;

on browsers supporting animation but not animation-fill-mode ?

Thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:59:07+00:00Added an answer on June 11, 2026 at 8:59 pm

    If it were me I’d try an opt for the simpler alternative – if possible. I’d downgrade my implementation so that I’m only using what is commonly accepted. Later on, when the feature is more widely supported I then think about implementing it. I rarely consider using a feature that has This is an experimental technology broadcast on documentation pages – but then maybe I should be classed as boring 🙂

    In your example, you could achieve the same result as animation-fill-mode:forwards by defining the end state of your element initially, and using a chained animation (if a delay before the action is needed):

    @keyframes waitandhide {
      from { opacity:0; }
      to { opacity:0; }
    }
    @keyframes show {
      from { opacity:0; }
      to { opacity:1; }
    }
    div {
      opacity:1;
      animation: waitandhide 2s 0s, show 2s 2s;
    }
    <div>just a test</div>​
    

    http://jsfiddle.net/RMJ8s/1/

    Now it is possible that slower browsers might flash up your initial element states before hiding them away again. But in my experience I’ve only seen this on very old machines and for pages that have a huge amount of css to render.

    Obviously the above does bloat your css a bit more (as you have to duplicate styles), and it would be more complicated when dealing with complex animations. However:

    1. It should work for pretty much any animation situation.
    2. It would avoid the need for JavaScript (save for the $().fadeIn fallback).
    3. It will work on all browsers that support css animation.
    4. You don’t run the risk of JS and CSS being/becoming unsynchronised.

    With regard to using short-forms it would be best not to if you want to go for as wide reaching browser compatibility as possible. However, as shown in my examples above I have opted for using short-forms because they hold more clarity and I can understand not wanting to write (or read) the long-winded versions all the time. For this reason I would recommend using less to generate your css:

    http://lesscss.org/

    http://radiatingstar.com/css-keyframes-animations-with-less

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So let me preface this by saying that I'm not an SQL wizard by
Let me preface by saying that I saw this other question on the subject
Let me preface this with, I come from a Java background. What is the
Let me preface by saying that I'm new to ant, and I'm using version
Let me preface this by saying that I'm well aware that running user supplied
Before asking the question let me preface with the fact that I am new
Ok, let me preface this question with the fact that I am extremely new
First, let me preface this by saying that I'm brand-new to Ember.js and relatively
Let me preface this by saying that my code seems to work for all
Let me preface the question by stating that I'm not a programmer and am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.