jQuery fadeOut without display none?

后端 未结 6 899
死守一世寂寞
死守一世寂寞 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:23

    You can use .animate() on the opacity directly:

    $(".selector").animate({ opacity: 0 })
    

    This way the element still occupies space like you want, it just has a 0 opacity, so it's effectively the same as it being visibility: hidden when it finishes.

提交回复
热议问题