2013-10-25 99 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>