2011-07-01 64 views

回答

11

Facebook做它的方式是讓所有不滾動的內容有positionfixed。通過這種方式,本地瀏覽器滾動條將顯示爲僅滾動中心區域,而實際上頁面的其餘部分固定就位。

A的這個非常簡單的例子:

http://jsfiddle.net/tcaVN/

現在想象之上,但與所有非滾動條目設置像#header

編輯

這裏有一個稍微複雜一點的例子,有三列:

http://jsfiddle.net/tcaVN/1/

2

其實,你所談論的div不滾動,其他div元件固定

這給大家的印象滾動條是div之外,當您實際滾動整個頁面,左邊和正確的div元素是固定的。即:通過使用樣式position: fixed;

+0

我想你的意思'位置外的滾動條:固定;',而不是'absolute'。 – Kokos

+1

@kokos:修改:) –

+0

不,「fixed」相對於窗口定位,「absolute」相對於文檔定位。如果您給「固定」div一個「絕對」的位置,他們仍然會滾動頁面的其餘部分。 http://jsfiddle.net/tcaVN/2/ – Kokos

1

我希望這可以幫助很多...看到你可以從這裏做什麼,我試圖在儘可能的代碼評論...

<html> 
<head> 
<title>Example</title> 
<style> 
#head{ 
position:fixed; /* this will make the div stay in the same place */ 
width:100%; /* this will size the dive to the width of the window */ 
height: 42px; /* this will make the height of the div 42px */ 
top:0px; /* make sure the div is at the very top */ 
left:0px; /* make sure the div is as far left as possible */ 
background: #009933; /* this will make the background of the div into a green color */ 
}#head_slack{ /* we make this one the same size so no text is ever covered */ 
width:100%; /* make sure the width of the slack is 100% */ 
height: 42px; /* make sure the hight of the slack is the same as the head fixed */ 
}body{ 
margin: 0px; /* takes out the default white border around the page */ 
}#leftFixed{ 
width 150px; /* set the width the same as the with of the table data cell containing the div */ 
position: fixed; /* make sure it stays in place */ 
left: 0px; /* make sure the div is at the left */ 
top: 45px; /* make sure the div is below the head div */ 
}#rightFixed{ 
width 200px; /* set the width the same as the with of the table data cell containing the div */ 
position: fixed; /* make sure it stays in place */ 
right: 0px; /* make sure the div is at the right */ 
top: 45px; /* make sure the div is below the head div */ 
} 
</style> 
</head> 
<body> 
<div id="head">This is the fixed header</div> 
<div id="head_slack">this is the header that takes the slack</div> 
<table width="100%"> 
<tr> 
<td width="150px" valign="top"> 
<div id="leftFixed">This is fixed content on the left</div> 
</td> 
<td> 
This is the scrollable content 
</td> 
<td width="200px" valign="top"> 
<div id="rightFixed">this is fixed content on the right</div> 
</td> 
</tr> 
</table> 
</body> 
</html> 
0

一個簡單的方法,我發現是:

#divID{ 
overflow: hidden; 
width: calc(1024px + 0); 
} 

#divID:hover{ 
overflow-y:scoll; 
} 

出於某種原因,這顯示在div