This is what worked for me (based on @Alan answer )
var foo = $('ul.load_details'); // or whatever var duration = "slow"; // or whatever if (foo.css('visibility') == 'visible') { foo.css({ opacity: 1 }).animate({ opacity: 0 }, duration, function () { foo.css({ visibility: "hidden" }); }); } else { foo.css({ opacity: 0 }).animate({ opacity: 1 }, duration).css({ visibility: "visible" }); }
When the foo element is visible, then slowly change the opacity to zero (via animate ), and then wait until this is done before the visibility of the foo visibility is displayed. Otherwise, if it is set to hidden during the animation process, the fading effect will not occur, since it is immediately hidden.
Alternatively, you can use a simpler, cleaner fadeTo () :
var foo = $('ul.load_details'); // or whatever var duration = "slow"; // or whatever if (foo.css('visibility') == 'visible') { foo.fadeTo(duration, 0, function () { foo.css({ visibility: "hidden" }); }); } else { foo.fadeTo(duration, 1).css({ visibility: "visible" }); }
Ray Vega Feb 06 '13 at 23:37 2013-02-06 23:37
source share