为什么jQuery显示/隐藏使用display:none而不是visibility:hidden? [英] Why does jQuery show/hide use display:none instead of visibility:hidden?

查看:208
本文介绍了为什么jQuery显示/隐藏使用display:none而不是visibility:hidden?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

display:none 表示该元素未呈现为DOM的一部分,因此在display属性更改为其他内容之前不会加载该元素。

display:none means that the element isn't rendered as part of the DOM, so it's not loaded until the display property changes to something else.

visibility:hidden 加载元素,但不显示它。

visibility:hidden loads the element, but does not show it.

为什么jQuery使用 display:none 表示其显示/隐藏功能,而不是在 visibility:hidden 和 visibility:visible

Why does jQuery use display:none for its show/hide functions instead of switching between visibility:hidden and visibility:visible?

推荐答案

因为在 display:none 中,出于各种目的,该元素不再存在 - 它不占用任何空间。
但是,在 visibility:hidden 中,就像你刚刚将 opacity:0 添加到元素中一样 - 它占用相同数量的空间,但只是不可见。

Because in display:none, the element, for all purposes, ceases to exist -- it doesn't occupy any space. However, in visibility:hidden, it's as if you had just added opacity:0 to the element -- it occupies the same amount of space but just acts invisible.

jQuery创建者可能认为前者更适合 .hide ()

The jQuery creators probably thought the former would be a better fit for .hide().

这篇关于为什么jQuery显示/隐藏使用display:none而不是visibility:hidden?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆