jQuery隐藏元素,同时保留页面布局中的空间 [英] jQuery hide element while preserving its space in page layout

查看:798
本文介绍了jQuery隐藏元素,同时保留页面布局中的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery中有一种方法可以隐藏元素,但在隐藏DOM时不会更改它吗?我隐藏了某个元素,但隐藏时,它下面的元素向上移动。我不希望这种情况发生。我希望空间保持不变,但要随意显示/隐藏元素。



我可以这样做吗?

(),使用:

  css('visibility','hidden')

hide()显示样式设置为 none ,它完全



visibility:hidden 保持空间不变照原样。


Is there a way in jQuery where I can hide an element, but not change the DOM when it's hidden? I'm hiding a certain element but when it's hidden, the elements below it move up. I don't want that to happen. I want the space to stay the same, but the element to be shown/hidden at will.

Can I do this?

解决方案

Instead of hide(), use:

css('visibility','hidden')

hide() sets the display style to none, which completely removes the element from the document flow and causes it to not take up space.

visibility:hidden keeps the space as it is.

这篇关于jQuery隐藏元素,同时保留页面布局中的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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