我在屏幕左侧有一个隐藏面板,单击位于屏幕左侧的“选项卡”会滑入视图。我需要面板滑过现有页面内容的顶部,并且我需要标签随之移动。所以两者都绝对定位在css中。一切正常,除了我需要标签(以及标签容器)在面板显示时随面板向左移动,因此它似乎粘在面板的右侧。使用浮动时相对简单,但这当然会影响现有内容的布局,因此会影响绝对定位。我已经尝试为面板容器的左侧位置设置动画(请参阅记录的 jquery 函数),但我无法让它工作。
这是我更改的原始代码的示例,我怎样才能让按钮/标签也滑动?
http://www.iamkreative.co.uk/jquery/slideout_div.html
我的 HTML
<div><!--sample page content-->
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
</p>
</div>
<div id="panel" class="height"> <!--the hidden panel -->
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore</p>
</div>
</div>
<!--if javascript is disabled use this link-->
<div id="tab-container" class="height">
<a href="#" onclick="return()">
<div id="tab"><!-- this will activate the panel. --></div>
</a>
</div>
我的 jQuery
$(document).ready(function(){
$("#panel, .content").hide(); //hides the panel and content from the user
$('#tab').toggle(function(){ //adding a toggle function to the #tab
$('#panel').stop().animate({width:"400px", opacity:0.8}, 100, //sliding the #panel to 400px
// THIS NEXT FUNCTION DOES NOT WORK -->
function() {
$('#tab-container').animate({left:"400px"} //400px to match the panel width
});
function() {
$('.content').fadeIn('slow'); //slides the content into view.
});
},
function(){ //when the #tab is next cliked
$('.content').fadeOut('slow', function() { //fade out the content
$('#panel').stop().animate({width:"0", opacity:0.1}, 500); //slide the #panel back to a width of 0
});
});
});
这是CSS
#panel {
position:absolute;
left:0px;
top:50px;
background-color:#999999;
height:500px;
display:none;/*hide the panel if Javascript is not running*/
}
#panel .content {
width:290px;
margin-left:30px;
}
#tab-container{
position:absolute;
top:20px;
width:50px;
height:620px;
background:#161616;
}
#tab {
width:50px;
height:150px;
margin-top:100px;
display:block;
cursor:pointer;
background:#DDD;
}
非常感谢