画面の左側に隠されたパネルがあり、画面の左側にある「タブ」をクリックするとスライドして表示されます。パネルを既存のページコンテンツの上にスライドさせる必要があり、タブを一緒に移動する必要があります。したがって、両方とも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;
}
どうもありがとう