JQuery hide不会删除对象的空间? [英] JQuery hide does not remove the space of the object?

查看:70
本文介绍了JQuery hide不会删除对象的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些jQuery代码隐藏列表项...

I am using some jQuery code where I hide a list item...

 $("ul.items").each(function() {
    $("li:gt(4)", this).hide();

我的问题是 .hide 似乎隐藏了元素,但仍然分配了它的空间。

My problem is that .hide seems to hide the element but the space for it is still allocated.

有没有办法删除这个空间...就像CSS上的 display:none 一样?

Is there a way to remove this space... like display:none on CSS does?

更新: .hide 实际上是带走元素,但其他元素没有向上拉伸以占用元素留下的空白。

UPDATE: .hide is actually taking away the element but the other elements are not stretching up to take the missing space left by the element.

推荐答案

嗯,这不应该发生。 $。fn.hide() sets display:none; not visibility:hidden; opacity:0; (这会隐藏元素,但会占用空间)。

Hmm that shouldn't happen. $.fn.hide() sets display: none; not visibility: hidden; or opacity: 0; (which would hide the element but keep its space occupied).

这大致相当于调用.css('display','none'),除了display属性的值保存在jQuery的数据cac中他以后可以将显示恢复到初始值 - 来自 http://api.jquery.com/hide /

"This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value" - from http://api.jquery.com/hide/.

编辑:你有没有用Firebug(或类似的)检查元素实际发生了什么?

Have you checked with Firebug (or similar) what actually happens to the element?

这篇关于JQuery hide不会删除对象的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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