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

前端 未结 3 774
抹茶落季
抹茶落季 2020-12-03 11:16

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

相关标签:
3条回答
  • 2020-12-03 11:30

    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>

    0 讨论(0)
  • 2020-12-03 11:42

    animate with css opacity seems to achieve a similar effect.

    $('#element').animate({opacity: 0}, 1000);
    

    Run the same with opacity: 1 to fade back in.

    Credit.

    0 讨论(0)
  • 2020-12-03 11:49

    Just Overwrite the property in the call back

    $('Element').on("click", function() {
        $(this).fadeOut(500, function() {
            $(this).css({"display": "block","visibility": "hidden"});  // <-- Style Overwrite 
        }); 
    })​
    
    0 讨论(0)
提交回复
热议问题