JQuery .hide() 没有定位丢失?
我有以下简单的脚本,可以在加载页面时使网页的元素淡入。
$('#box1').hide();
$('#box1').delay(300).fadeIn(500);
我遇到的问题是,当隐藏时,#box1
不占用任何空间(因为它的类是可见的:none)。如何隐藏 #box1
以便它不会破坏依赖于其存在的其他浮动元素?
I have the following simple script to make an element of my webpage fade in as the page is loaded.
$('#box1').hide();
$('#box1').delay(300).fadeIn(500);
The problem I have is that when hidden, #box1
takes up no space (due to its class being visible:none). How can I hide #box1
so it doesn't disrupt other floated elements that depend on its presence?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不知道您的情况是否可行,但您可以设置元素的不透明度,
然后
Don't know if that's possible in your case but you could just set the opacity of the element,
then
将
#box1
放入包装器中并为其指定宽度和高度。现在,当您隐藏 #box1 时,包装器保持为空。Put
#box1
in a wrapper and give it a width and height. Now when you hide #box1, wrapper stay empty.该代码可以正常工作,不会丢失位置,也不会崩溃。
(隐藏)
(显示)
This code works without losing position and does not collapse.
(hide)
(show)
JQuery的hidden相当于将display设置为none。目前这与:
相反,尝试首先将对象上的 css 类设置为无可见性。比如:
然后
JQuery's hidden is the equivalent of setting the display to none. This is the same currently as:
Instead try first setting the css class on the object to have a visibility of none. Something like:
Then