jQuery fadeOut without display none?

后端 未结 6 911
死守一世寂寞
死守一世寂寞 2020-12-08 03:54

Is there an alternative to fadeOut() that doesn\'t use display:none for the style? I\'d like to just use visibility hidden to avoid any sort of shifting in the page layout?

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 04:26

    One way of doing this is to capture the display mode, then .fadeOut, and in the complete, do your preferred method of hiding, and set the display back to what it was:

    var $element = $('#selector');
    
    var display = $element.css('display');
    $element.fadeOut(500, function() {
       $element.css('visibility', 'hidden'); 
       $element.css('display', display);
    }
    

提交回复
热议问题