17

I found this question CSS Auto hide elements after 5 seconds

and I need to know how to do the oposite of this. Basically:

-Page loads with element hidden

-Wait 5 seconds

-Show element

I'm not very good with CSS so Any help would be nice!

#thingtohide {
    -moz-animation: cssAnimation 0s ease-in 5s forwards;
    /* Firefox */
    -webkit-animation: cssAnimation 0s ease-in 5s forwards;
    /* Safari and Chrome */
    -o-animation: cssAnimation 0s ease-in 5s forwards;
    /* Opera */
    animation: cssAnimation 0s ease-in 5s forwards;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}

@keyframes cssAnimation {
    to {
        width:0;
        height:0;
        overflow:hidden;
    }
}
@-webkit-keyframes cssAnimation {
    to {
        width:0;
        height:0;
        visibility:hidden;
    }
}
Dylan Grove
  • 493
  • 1
  • 7
  • 17
  • 1
    This is literally a case of swapping out the properties between the end and beginning states from the target question you linked. – TylerH Oct 17 '17 at 20:58
  • @MattWeber introducing a library that depends on another programming language is not in any way simpler than using CSS to show a hidden element after 5 seconds. – TylerH Oct 17 '17 at 21:00
  • 2
    @TylerH According to the answers there is a better way to do the inverse, additionally, I didn't know what needed to be changed an I had already played around with it but had no success. Hence why I made a new question instead of necroing that old thread. – Dylan Grove Oct 17 '17 at 21:30
  • 1
    Don't ever worry about posting to an old Q&A page. This isn't a forum, so there's no problem with asking for clarification on an old question or answer, so long as it is pertinent. – TylerH Oct 17 '17 at 21:34

2 Answers2

34

try this simple solution.

#showMe {
  animation: cssAnimation 0s 5s forwards;
  visibility: hidden;
}

@keyframes cssAnimation {
  to   { visibility: visible; }
}
<div id='showMe'>Wait for it...</div>

You can also use opacity insted of visibility

#showMe {
  animation: cssAnimation 0s 5s forwards;
  opacity: 0; 
}

@keyframes cssAnimation {
  to   { opacity: 1; }
}
<div id='showMe'>Wait for it...</div>
Jayakrishnan
  • 1,295
  • 2
  • 13
  • 27
6

You can run something like this. This sets the opacity to 0 and after a few seconds, it ramps it back to 100%. This option allows you to fine tune how quickly you want it to appear, giving you control over how much opacity the element would have and when in the timeframe it would have it.

#showMe {
    opacity: 0;
    -moz-animation: cssAnimation 5s;
    /* Firefox */
    -webkit-animation: cssAnimation 5s;
    /* Safari and Chrome */
    -o-animation: cssAnimation 5s;
    /* Opera */
    animation: cssAnimation 5s;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}
@keyframes cssAnimation {
    99% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
@-webkit-keyframes cssAnimation {
    99% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
<div id='showMe'>Wait for it...</div>
yohohosilver
  • 367
  • 1
  • 2
  • 15
  • 2
    you can use `cssAnimation 0s 5s forwards;` and get rid of 99% in keyframe, it will create a delay of 5s and no animation time – Jayakrishnan Oct 17 '17 at 20:56
  • Good call, I set the answer the way it was to allow for the asker to see they can adjust and set the opacity and the timeframes associated. This way they can set opacity to slowly go to 50% over 2 seconds then on then quickly to 100 on the 3rd... so on and so forth. – yohohosilver Oct 17 '17 at 20:57