Is it possible to hide element 5 seconds after the page load? I know there is a jQuery solution.
I want to do exactly same thing, but hoping to get the same result with CSS transition.
Any innovative idea? Or am I asking beyond the limit of css transition/animation?
Why not try fadeOut?
fadeOut (Javascript Pure):
How to make fadeOut effect with pure JavaScript
based from the answer of @SW4, you could also add a little animation at the end.
Making the remaining 0.5 seconds to animate the opacity attribute. Just make sure to do the math if you're changing the length, in this case, 90% of 5 seconds leaves us 0.5 seconds to animate the opacity.
YES!
But you can't do it in the way you may immediately think, because you cant animate or create a transition around the properties you'd otherwise rely on (e.g.
display
, or changing dimensions and setting tooverflow:hidden
) in order to correctly hide the element and prevent it from taking up visible space.Therefore, create an animation for the elements in question, and simply toggle
visibility:hidden;
after 5 seconds, whilst also setting height and width to zero to prevent the element from still occupying space in the DOM flow.FIDDLE
CSS
HTML
Of course you can, just use
setTimeout
to change a class or something to trigger the transition.HTML:
CSS:
JS to run on load or DOMContentReady:
Example fiddle here.