2011-08-03 28 views
4

1)如果您有Google Plus帳戶,請轉到您的主頁。像Google Plus一樣劫持頁面滾動?

2)在右側,有一個可以懸停的「添加到圓形」按鈕的列表。 3)請注意,當您將鼠標懸停在「添加到圈子」下拉列表中的某個上時(如果您有足夠多的圓圈可以在下拉列表中滾動),頁面滾動功能將被禁用。只允許在下拉列表中垂直滾動。

這是怎麼做到的JavaScript?

enter image description here

我可以在這裏滾動(右邊的滾動條),但同時這也是跌坐在頁面主體不能滾動。

回答

9

將有一個具有固定的高度和溢出汽車的元素,他們的風格滾動條用這一招:http://beautifulpixels.com/goodies/create-custom-webkit-scrollbar/

你可以使它在FF和IE瀏覽器的工作:基本上,你巢是溢出元素自動進入另一個頁面,並用負邊距隱藏滾動條。然後在同一個元素上捕獲滾動事件,並根據scrollTop位置調整右側的滑塊。

下面是我會做:http://jsfiddle.net/kGbbP/4/

但也有很多jQuery插件,可以這樣做: http://www.net-kit.com/jquery-custom-scrollbar-plugins/

+0

我怎麼能實現呢我自己? (讚賞基本步驟。) –

+0

另外:如何捕獲瀏覽器滾動事件?這些插件似乎都無法做到這一點。 –

+0

@Max Hoff:你在這裏:http://jsfiddle.net/kGbbP/4/ – meo

8

這不是通過JavaScript做!

這是純粹的CSS,只適用於(非移動)基於webkit的瀏覽器。

這裏是CSS代碼,只需將其包含在CSS文件中,將其附加到HTML文檔,然後運行.html文件。 這裏是一個演示:http://jsfiddle.net/3ZqGu/

這裏是CSS代碼:

::-webkit-scrollbar { 
background:transparent;overflow:visible; width:15px;} 
::-webkit-scrollbar-thumb { 
background-color:rgba(0,0,0,0.2); border:solid #fff;} 
::-webkit-scrollbar-thumb:hover { 
background:rgba(0,0,0,0.4);} 
::-webkit-scrollbar-thumb:horizontal { 
border-width:4px 6px;min-width:40px;} 
::-webkit-scrollbar-thumb:vertical { 
border-width:6px 4px;min-height:40px;} 
::-webkit-scrollbar-track-piece{ 
background-color:#fff;} 
::-webkit-scrollbar-corner { 
background:transparent;} 
::-webkit-scrollbar-thumb { 
background-color: #DDD;} 
::-webkit-scrollbar-thumb:hover { 
background-color: #999;} 
相關問題