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?
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.
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.
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%.
$("div"). animate({ opacity:0 },"slow"); This is useful if you also want to animate other properties of the element at the same time.
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>
Just Overwrite the property in the call back
$('Element').on("click", function() {
$(this).fadeOut(500, function() {
$(this).css({"display": "block","visibility": "hidden"}); // <-- Style Overwrite
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With