0

我有两个 div,我想在它们之间切换。

主 div 用于侧面导航,还包含图像和菜单列表。

我可以使两个 div 切换,但主 div 内的内容也不会切换。

<div class="wide">
<img src="images/logo150.png" width="150" height="90">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Latest News</a></li>
</ul>
</div>

<script>
$( ".wide" ).click(function() {  
$( this ).toggleClass( "narrow", 1000, "easeOutSine" );
});
</script>

<style>
html {
margin: 0px;
padding: 0px;
height: 100%;
}
body {
height: 100%;
margin: 0px;
padding: 0px;
background-image: url(load/images/1.jpg);
background-repeat: no-repeat;
background-position: left top;
}   
.wide {
width: 150px;
height: 100%;
position: fixed;
z-index: 1000;
min-height: 1000%;
background-color: rgba(0,0,0,0.8);
padding-top: 50px;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 20px;
cursor: pointer;
}  
.narrow {
width: 50px;
height: 100%;
position: fixed;
z-index: 10;
min-height: 1000%;
padding-top: 50px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
cursor: pointer;
background-color: rgba(0,0,0,0.8);
background-image: url(logotop.png);
background-repeat: no-repeat;
background-position: center top;
}  
</style>

http://jsfiddle.net/jCcg7/

非常感谢任何帮助,因为我是 jQuery 的新手,并且我确信这可以完成。

谢谢

4

2 回答 2

1

You are toggling the class of the containing element (.wide) to 50px wide, but the contents (e.g. img) are fixed at 150px - therefore they will overflow.

In the .narrow class you need to hide this overflow using:

overflow: hidden;
于 2013-11-14T14:44:23.457 回答
1

您需要使用 CSS 规则隐藏收缩元素的“溢出”。

overflow:hidden; /* Inside .narrow */

见这里:http: //jsfiddle.net/jCcg7/3/

于 2013-11-14T14:40:48.347 回答