Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to use jquery fade in effects, but want to use visibility:hidden initially

Tags:

jquery

It seems most of the jquery fadein/out and animate functions are based on the initial element having display:none as opposed to visibility:hidden.

What if I want the initial element to take space up on the page (i.e. use visibility:hidden), but then use a fade in/out or slide effect? Is there an easy way to do this?

like image 536
phpmysqlguy Avatar asked Nov 06 '13 16:11

phpmysqlguy


People also ask

How do you animate visibility hidden?

css({opacity: 1.0, visibility: "hidden"}). animate({opacity: 0}, 1200); },function(){ $('. class'). css({opacity: 0.0, visibility: "visible"}).

How to set fadeOut time in jQuery?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector). fadeOut(speed,callback);

What is fade in and fadeOut in jQuery?

You can use the jQuery fadeIn() and fadeOut() methods to display or hide the HTML elements by gradually increasing or decreasing their opacity.

How to stop fadeOut jQuery?

stop(). animate({opacity:'100'}) combo is what allows any fadIn/fadeOut to restart based on your trigger.


2 Answers

Sure, start with visibility: hidden then do:

$('.your-element').css('visibility','visible').hide().fadeIn();

Borrowed from a very similar question.

like image 122
hiattp Avatar answered Oct 11 '22 12:10

hiattp


You may also try something like this (Demo) as fadeIn

$('div').css({opacity: 0, visibility: "visible"}).animate({opacity: 1}, 'slow');
like image 37
The Alpha Avatar answered Oct 11 '22 12:10

The Alpha