我有一个左侧导航器,我想让它在用户命令中隐藏。
“我隐藏导航”按钮应该在点击后保持可见,停留在相同的垂直空间,并在再次显示导航时将自己重新定位到原始位置。我如何才能做到这一点呢?如果需要,我可以更改html,我知道当你使用display:none时,它的子项都不会显示,流程也会改变,这样按钮就不会停留在相同的垂直位置。我也可以改变设计,所以如果你有更好的主意,我洗耳恭听。但是,这应该对用户尽可能友好,如果我将按钮从垂直位置移动,人们可能会感到困惑,这就是为什么我想让它留在那里。
发布于 2012-08-02 22:42:32
问题主要出在您的标记上。"I hide the nav button“包含在#leftNavigator中,所以当您隐藏#leftNavigator时,您同时也隐藏了您希望保持可见的按钮。有许多方法可以修改您的标记以使其工作。
从本质上讲,我只是为导航器创建了一个包装器,并将其相对定位,在其中我绝对定位了“我隐藏导航按钮”。我还在两个控制面板按钮上增加了一个上边距,以便为“我隐藏导航”按钮留出空间。有很多方法可以实现这一点。
#leftNavigator{float:left; width:100%; background-color:red;}
#top{height:150px; background-color:blue;}
#controlPanel{height:50px; background-color:gray;}
#tree{background-color:green;}
#content{overflow:auto; background-color:coffee;}
#btn{z-index:10;position:absolute;top:150px;}
#navigator_wrapper{position:relative;height:150px;width:20%}
#controlPanel button {margin-top:25px;}
<div id="navigator_wrapper">
<button id="btn">I hide the nav</button>
<div id="leftNavigator">
<div id="top">I have an image</div>
<div id="controlPanel"><button>Other</button><button>controls</button></div>
<div id="tree">I'm a jstree</div>
</div>
</diV>
<div id="content">
I take all the space I want. Except for leftNavigator's space.
</div>这是一个jfiddle http://jsfiddle.net/samisadaka/9c7va/
发布于 2012-08-02 22:40:00
这是Joe的小提琴的一个稍微不同的版本。它可以通过改变视觉效果来保持遮挡效果。
$("#leftNavigator").animate({
"opacity" : 0.0
});发布于 2012-08-02 22:44:09
您可以解决将<button>移出div的问题。
我摆弄了你的小提琴:http://jsfiddle.net/3Cam3/
基本上,将您的HTML更改为如下所示:
<button id="btn">I hide the nav</button>
<div id="leftNavigator">
<div id="top">I have an image</div>
<div id="controlPanel"><button>Other</button><button>controls</button></div>
<div id="tree">I'm a jstree</div>
</div>
<div id="content">
I take all the space I want. Except for leftNavigator's space.
</div>按钮将固定在它所在的位置(因为它是position: absolute)并且不会随div一起消失。
https://stackoverflow.com/questions/11779602
复制相似问题