偏离了 crowjonah 的解决方案,并提出了一些我认为更接近您的规范的方法。
在这里查看:
http://jsfiddle.net/VLNDL/
首先,对 div 进行了一些重组,使展开/收缩按钮与滑动 div 是对等的;以便它在过渡期间保持连接:
<div id="intro-wrap">
<div class="open-intro">+</div>
<div class="close-intro">-</div>
<div id="contentWrap">
<h1 class="main-header">Here is a Title</h1>
<p class="main-desc">You can write whatever you want about yourself here. You can say you're a superhuman alien ant, arrived from the nether regions of Dwarf-Ant-Dom.</p>
</div>
然后将 CSS 重构为:1. 让它更简单一点,2:围绕块、相对、浮动和绝对进行更改,以便将按钮“固定”到相对 div,就是这样:
#intro-wrap {
position: relative;
z-index: 1;
border-left: 25px solid rgba(0,0,0,.2);
width: 200px;
}
#contentWrap{
background: rgba(0,0,0,.8);
padding: 15px 40px 25px 30px;
}
#intro-wrap h1 {
font-family: "PT Sans Narrow";
font-size: 25px;
color: #fff;
font-weight: 700;
margin-bottom: 0px !important;
padding-bottom: 10px;
}
#intro-wrap p {
line-height: 19px;
color: #999;
}
.open-intro,
.close-intro {
position:absolute;
left:200px;
cursor: pointer;
width: 25px;
height: 25px;
z-index: 50;
padding-left:15px;
}
.open-intro {
display: none;
background: yellow
}
.close-intro {
background: red;
}
我在 js 中唯一改变的是我禁用了不透明动画,但你可以把它带回来——我只是不会用它来定位 #intro-wrap,你应该用它来定位 contentWrap:
$('.open-intro').click(function() {
$('#intro-wrap').animate({
//opacity: 1,
left: '0',
}, 500, function() {
// Animation complete.
});
$('.open-intro').hide();
$('.close-intro').show();
});
$('.close-intro').click(function() {
$('#intro-wrap').animate({
//opacity: 0.25,
left: '-225',
}, 400, function() {
// Animation complete.
});
$('.open-intro').show();
$('.close-intro').hide();
});
J