2013-10-25 98 views
7

我想隱藏頁面中的滾動條,但我可以滾動,就像它有一個滾動條。 所以我不能使用溢出:隱藏,因爲我想我可以滾動像正常 但無法看到滾動條。在Firefox中隱藏滾動條

所以我用這個CSS代碼(類不滾動體是一類體標記的)

.not-scroll-body::-webkit-scrollbar { 
    display: none; 
} 

它可以在Chrome,但是當我使用-moz-,而不是-webkit-這樣

.not-scroll-body::-moz-scrollbar { 
    display: none; 
} 

它在Firefox中不起作用。

我能做些什麼才能使它工作?

感謝您的每一個答案,和我那可憐的英語:)

+1

爲什麼不同時使用? –

+1

另外,歡迎來到StackOverflow,你的英文很好:) –

+0

@christian其實,我在我的代碼中都使用它,但它只適用於Chrome,不適用於Firefox:') – Mei

回答

4

根據this answer和一切我已經能夠在網上找到,沒有火狐相當於-webkit-scrollbar選擇的遺憾。顯然有used to be屬性,-moz-scrollbars-none,你可以使用這個,但它已被刪除和人recommend使用overflow:hidden或hackish margin-right: -14px解決方案。

對不起,我不能更有幫助 - 似乎沒有Firefox的方式來優雅地做到這一點。

+1

我嘗試了margin-right:-14px,但是滾動條沒有改變位置(它沒有發生任何事情),雖然裏面的內容改變位置右邊(從margin-right -14) – Mei

+0

但你的回答是非常有幫助的,非常感謝你:D – Mei

+0

หมีเมืองทอง - 確保父元素是'overflow:hidden' –

4

我能夠隱藏滾動條,但仍然能夠滾動使用鼠標滾輪使用此解決方案:

html {overflow: -moz-scrollbars-none;} 

下載插件https://github.com/brandonaaron/jquery-mousewheel,包括這樣的功能:

jQuery('html,body').bind('mousewheel', function(event) { 
    event.preventDefault(); 
    var scrollTop = this.scrollTop; 
    this.scrollTop = (scrollTop + ((event.deltaY * event.deltaFactor) * -1)); 
    //console.log(event.deltaY, event.deltaFactor, event.originalEvent.deltaMode, event.originalEvent.wheelDelta); 
    }); 
0

我假設你要在本地隱藏滾動條。我的意思是,不是在世界上看到的Web服務器上,而是在你本地的Firefox副本上,僅僅是爲了你的「觀看愉悅」。

這是我發現在userChrome.css中的opensuse/kde: 上工作的;

#content browser { 
margin-right -12px !important; 
overflow-x:hidden; 
overflow-y:scroll; 
} 

使用-14px來完全隱藏垂直滾動(如果您的系統主題具有更寬的滾動設置,則會更多)。我使用less(10px)來查看它的一小部分,以便我可以中鍵單擊以跳轉到頁面上的某個位置。

件事,我做到了,但並不總是工作,不再: 在userContent.css

#content browser { 
overflow:-moz-scrollbars-none; 
} 

- 或 -

html { 
overflow: -moz-scrollbars-none;} 
} 

上面使用的工作,但我現在我丟失了鼠標滾輪。現在只有鍵盤箭頭鍵可以工作。

希望我明白你想要什麼,這有助於。 蘭迪斯。

1

CF:https://stackoverflow.com/a/41021131/4881677

這是我如何做到這一點,只有CSS和與像引導框架效果很好。它只需要2個額外的div:

如果您有觸摸屏,您可以選擇文本使其滾動或用手指滾動。

.overflow-x-scroll-no-scrollbar {overflow:hidden;} 
 
.overflow-x-scroll-no-scrollbar div { 
 
    overflow-x:hidden; 
 
    margin-bottom:-17px; 
 
    overflow-y:hidden; 
 
    width:100%; 
 
} 
 
.overflow-x-scroll-no-scrollbar div * { 
 
    overflow-x:auto; 
 
    width:100%; 
 
    padding-bottom:17px; 
 
    white-space: nowrap; 
 
    cursor:pointer 
 
} 
 

 
/* the following classes are only here to make the example looks nicer */ 
 
.row {width:100%} 
 
.col-xs-4 {width:33%;float:left} 
 
.col-xs-3 {width:25%;float:left} 
 
.bg-gray{background-color:#DDDDDD} 
 
.bg-orange{background-color:#FF9966} 
 
.bg-blue{background-color:#6699FF} 
 
.bg-orange-light{background-color:#FFAA88} 
 
.bg-blue-light{background-color:#88AAFF}
<html><body> 
 
    <div class="row"> 
 
    <div class="col-xs-4 bg-orange">Column 1</div> 
 
    <div class="col-xs-3 bg-gray">Column 2</div> 
 
    <div class="col-xs-4 bg-blue">Column 3</div> 
 
    </div> 
 
    <div class="row"> 
 
    <div class="col-xs-4 bg-orange-light">Content 1</div> 
 
    <div class="col-xs-3 overflow-x-scroll-no-scrollbar"> 
 
     <div> 
 
     <div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div> 
 
     </div> 
 
    </div> 
 
    <div class="col-xs-4 bg-blue-light">Content 3</div> 
 
    </div> 
 
</body></html>

短版懶人:

.overflow-x-scroll-no-scrollbar {overflow:hidden;} 
 
.overflow-x-scroll-no-scrollbar div { 
 
    overflow-x:hidden; 
 
    margin-bottom:-17px; 
 
    overflow-y:hidden; 
 
    width:100%; 
 
} 
 
.overflow-x-scroll-no-scrollbar div * { 
 
    overflow-x:auto; 
 
    width:100%; 
 
    padding-bottom:17px; 
 
    white-space: nowrap; 
 
    cursor:pointer 
 
} 
 

 
/* the following classes are only here to make the example looks nicer */ 
 
.parent-style {width:100px;background-color:#FF9966}
<div class="parent-style overflow-x-scroll-no-scrollbar"> 
 
    <div> 
 
    <div>This content too long for the container, so it needs to be hidden but scrollable without scrollbars</div> 
 
    </div> 
 
</div>