2012-11-15 111 views
0

我試圖複製facebook手機網站,你點擊一個菜單按鈕,左邊的菜單出現。我遇到的問題是我希望自己的內容區域寬度達到100%,但當隱藏的菜單顯示100%的內容區域下降到菜單下時。jQuery的切換內容區域移動以下顯示區域

下面是js小提琴:jsfiddle 代碼如下所示。

預先感謝任何答覆

HTML

<div id="menu"> 
</div> 
<div id="content"> 
    <div id="header"> 
     <div id="menuButton"> 
     </div> 
    </div> 
</div>​ 

CSS

body{padding:0px; margin:0px; width:100%; min-width:320px; height:100%; min-height:480px; background-color:#FFFFFF;} 
#menu{ width:240px; min-width:240px; height:100%; min-height:480px; float:left; background-color:#CCCCCC; display:none; position:relative;} 
#header{ height:48px; width:100%; min-height:48px; min-width:320px; background-color:#666666; float:left;} 
#menuButton{ width:30px; height:30px; background-color:#999999;margin-top:9px; margin-left:15px;} 
#content{ float:left; min-width:320px; min-height:480px; width:100%;} 

jQuery的

$("#menuButton").click(function() { 
    $('#menu').toggle(),750; 
}); ​ 
+0

這是什麼意思? '100%的內容區域下降到菜單下方。' – VIDesignz

+0

看起來你的小提琴在工作......你能解釋一下嗎?也許增加不同的背景顏色來幫助解釋你想要做什麼? – VIDesignz

+0

在小提琴中,包含按鈕的標題在菜單下方下降,我只是希望它向右移動240px。我更新了小提琴,將內容區域顯示爲灰色,以顯示內容區域向下移動而不是正確。 – huddds

回答

1

這避免了水平滾動條從彈出,另外,填充頂部以便內容實際顯示。

FIDDLE

$("body").on('click', '#menuButton', function() { 

     if($('#container').position().left === 0){ 
      $('#container').css({'left' : 240 , 'width' : $('#container').width() - 240 }); 
     }else{ 
      $('#container').css({'left' : 0, 'width' : '100%'}); 
     } 

     $('#menu').toggle(); 
    }); 
+0

這絕對是排序標題,但灰色內容區域仍然下降。 – huddds

+0

@huddds所以你想要的內容是在菜單下?或者像標題一樣移動過來? – VIDesignz

+1

@VIDesignz你幾乎正確的只是你需要在另一個div中包裝'#header'和'#content'並將腳本應用到它們。工作[小提琴](http://jsfiddle.net/EssVx/5/) –