Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div gets hidden after CSS animating

I have a delayed animation on page load with CSS3. Everything works fine, but after the animation is done, the DIV goes back into visibility: hidden.

.content-left {
    margin-left: 100px;
    margin-top: 32px;
    position: absolute;
    z-index: 1; 
    visibility: hidden;
    -webkit-animation: fadein 1s 2s ease; /* Safari and Chrome */
    animation: fadein 1s 2s ease;
}

@keyframes fadein {
from { height: 0px; }
to   { height: 421px; visibility: visible;} }

@-webkit-keyframes fadein {
from { height: 0px; }
to   { height: 421px; visibility: visible;}}
like image 418
Helmut Avatar asked Mar 19 '23 01:03

Helmut


2 Answers

That happens because once the animation is done, it reverts back to the original styling.

you can however, direct your animation to keep the last frame of the animation after its done playing, its called Animation Fill Mode

animation-fill-mode: forwards; - will keep the last frame of the animation.
animation-fill-mode: backwards; - will keep the first frame of the animation.

or you can add forwards to your animation declaration:

-webkit-animation: fadein 1s 2s ease forwards; /* Safari and Chrome */
animation: fadein 1s 2s ease forwards;
like image 158
Banana Avatar answered Mar 27 '23 22:03

Banana


set animation-fill-mode: forwards so it will not go back to first stage of the animation.

like image 30
rob Avatar answered Mar 27 '23 21:03

rob