Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The .fadeOut() method to use visibility property instead of display property

The .fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none, so the element no longer affects the layout of the page and same is for fadeIn().

My Question is can they use visibility property so they the element occupy the space in layout of the page and is not just visible?

like image 230
GajendraSinghParihar Avatar asked Aug 29 '12 05:08

GajendraSinghParihar


People also ask

What is fadeOut in jQuery?

jQuery Effect fadeOut() Method The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (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 fadeIn() method.

What is fadeIn and fadeOut in jQuery?

The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent. Note – jQuery does the fading by changing the opacity of the element.

What is a fade function?

The Less Fade function is used to set the transparency of the color for selected elements. The parameters used for fade function are: color: It is used to specify color object. amount: Its percentage varies between 0 - 100%.

How do you make a div appear slowly CSS?

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


Video Answer


2 Answers

Use jQuery's fadeTo() and then have a callback set the visibility. Example:

$('#fade').on("click", function(){
    $(this).fadeTo(500, 0, function(){
        $(this).css("visibility", "hidden")
    }) // duration, opacity, callback
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<a href="#" id="fade">Click to Fade</a>
<div>This won't move</div>
like image 119
methodofaction Avatar answered Sep 18 '22 19:09

methodofaction


Just Overwrite the property in the call back

$('Element').on("click", function() {
    $(this).fadeOut(500, function() {
        $(this).css({"display": "block","visibility": "hidden"});  // <-- Style Overwrite 
    }); 
})​
like image 34
Gajendra Singh Parihar Avatar answered Sep 16 '22 19:09

Gajendra Singh Parihar