Css3 disappears when the page loads, after seconds

I searched around stackoverflow for an answer for a while, but it seems to me that this has not been interrogated before.

excuses if I might have missed the answer somewhere, but here it goes:

So, I am working on a page that disappears in a div on the page load, now I want it to disappear after a few seconds. I cannot find the right way to do this.

@-webkit-keyframes fadein {
from {
opacity:0;
}
to {
opacity:1;
}
}
@-webkit-keyframes fadeout {
from {
    opacity:1;
}
to {
    opacity:0;
}
}
div {
width: 400px;
margin: 0 auto;
text-align: center;
-webkit-animation:fadein 1s;
-webkit-animation:fadeout 1s;
-webkit-animation-delay:fadeout 5s;
}

html:

 <div>
 <h1><font size="+6"> :(</font></h1><br />
 <h1>Whoops<span>Something went wrong</span></h1><br />
 <h1><span><div id="timer_div">you will be redirected in</div> seconds</span></h1>
 </div>
+3
source share
4 answers

Your problem is with the simultaneous use of two animations that you really want to perform sequentially. To ensure reliable operation, you have two options:

CSS only: http://jsfiddle.net/marionebl/M9LR6/

opacity: 0;, . : IE <= 9, : http://caniuse.com/#feat=css-animation

@keyframes fadeInOut {
    0% {
        opacity: 0;
    }
    16% {
       opacity: 1;
    }
    84% {
       opacity: 1;
    }
    100% {
       opacity: 0;
    }
}

.message {
    width: 400px;
    margin: 0 auto;
    opacity: 0;
    text-align: center;
   -webkit-animation: fadeInOut 6s;
   animation: fadeInOut 6s;
}

JS: http://jsfiddle.net/marionebl/P26c9/1/

, IE9.

CSS

@-webkit-keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@-webkit-keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}
@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.fadeIn {
    -webkit-animation: fadeIn;
    animation: fadeIn;
    opacity: 1;
}

.fadeOut {
    -webkit-animation: fadeOut;
    animation: fadeOut;
    opacity: 0;
}

.fast {
    -webkit-animation-duration: 1s;
    animation-duration: 1s
}

.message {
    width: 400px;
    margin: 0 auto;
    text-align: center;
}

JS:

var $message = $('.message');
$message.addClass('fadeIn fast');

setTimeout(function(){
   $message.removeClass('fadeIn').addClass('fadeOut');
}, 5000);
+8

: http://jsfiddle.net/maximgladkov/YR5UM/

@-webkit-keyframes fade {
    0% {
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

div {
    width: 400px;
    margin: 0 auto;
    text-align: center;
    -webkit-animation: fade 6s;
    -webkit-animation-fill-mode: both;
}
+2

Have you tried the delay in this form?

transition-delay: 2s;
-webkit-transition-delay: 2s; /* Safari */

or

animation-delay:2s;
-webkit-animation-delay:2s; /* Safari and Chrome */
0
source

Use jquery animations.

$(document).ready(function(){
$('.div').delay(2000).animate({opacity:100},1000)
})

This will linger for 2 seconds when the page loads, and then the div will disappear.

0
source

All Articles