perhaps? 2013-05-21 13:11 采纳率: 100%
浏览 3303
已采纳

隐藏滚动条,但仍然能够滚动

我希望能够滚动整个页面,但不显示滚动条。

在谷歌浏览器中:

::-webkit-scrollbar { 
    display: none; 
}
但是Mozilla Firefox和Internet Explorer似乎无法正常工作。 我也在CSS中尝试过:
overflow: hidden;

那确实隐藏了滚动条,但我无法滚动了。 有什么办法可以删除滚动条,同时仍然可以滚动整个页面? 仅使用CSS或HTML。请帮助我。

转载于:https://stackoverflow.com/questions/16670931/hide-scroll-bar-but-while-still-being-able-to-scroll

  • 写回答

23条回答 默认 最新

  • 衫裤跑路 2013-05-21 13:37
    关注

    Just a test which is working fine.

    #parent{
        height: 100%;
        width: 100%;
        overflow: hidden;
    }
    
    #child{
        width: 100%;
        height: 100%;
        overflow-y: scroll;
        padding-right: 17px; /* Increase/decrease this value for cross-browser compatibility */
        box-sizing: content-box; /* So the width will be 100% + 17px */
    }
    

    Working Fiddle

    JavaScript:

    Since, the scrollbar width differs in different browsers, it is better to handle it with JavaScript. If you do Element.offsetWidth - Element.clientWidth, the exact scrollbar width will show up.

    JavaScript Working Fiddle

    or

    Using Position: absolute,

    #parent{
        height: 100%;
        width: 100%;
        overflow: hidden;
        position: relative;
    }
    
    #child{
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: -17px; /* Increase/Decrease this value for cross-browser compatibility */
        overflow-y: scroll;
    }
    

    Working Fiddle

    JavaScript Working Fiddle

    Info:

    Based on this answer, I created a simple scroll plugin. I hope this will help someone.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(22条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?