Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fading visibility of element using jQuery

I'm having some trouble with finding the visibility param for JQuery.

Basically... the code below does nothing.

$('ul.load_details').animate({     visibility: "visible"     },1000); 

There's nothing wrong with the animate code (I replaced visibility with fontSize and it was fine. I just can't seem to find the correct param name equivalent for "visibility" in css.

like image 595
Jieren Avatar asked Jun 23 '09 11:06

Jieren


People also ask

What is fading in jQuery?

jQuery fadeIn() Method The fadeIn() method gradually changes the opacity, for selected elements, from hidden to visible (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeOut() method.

How do I make a div appear slower?

$("div"). animate({ opacity:0 },"slow"); This is useful if you also want to animate other properties of the element at the same time.

Which function is used to show an element with the fade effect?

The fadeIn() function is used to show a hidden element in HTML.


2 Answers

You could set the opacity to 0.0 (i.e. "invisible") and visibility to visible (to make the opacity relevant), then animate the opacity from 0.0 to 1.0 (to fade it in):

$('ul.load_details').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0}); 

Because you set the opacity to 0.0, it's invisible despite being set to "visible". The opacity animation should give you the fade-in you're looking for.

Or, of course, you could use the .show() or .fadeTo() animations.

EDIT: Volomike is correct. CSS of course specifies that opacity takes a value between 0.0 and 1.0, not between 0 and 100. Fixed.

like image 176
Alan Plum Avatar answered Oct 08 '22 13:10

Alan Plum


Maybe you are just looking to show or hide an element:

$('ul.load_details').show(); $('ul.load_details').hide(); 

Or do you want to show/hide element using animation (this doesn't make sense of course as it will not fade):

$('ul.load_details').animate({opacity:"show"}); $('ul.load_details').animate({opacity:"hide"}); 

Or do you want to really fade-in the element like this:

$('ul.load_details').animate({opacity:1}); $('ul.load_details').animate({opacity:0}); 

Maybe a nice tutorial will help you get up to speed with jQuery:

http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/

like image 27
Michiel Avatar answered Oct 08 '22 11:10

Michiel