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

在Google Chrome中,它是:

::-webkit-scrollbar {
    display: none;
}

但Mozilla Firefox和Internet Explorer似乎不是这样工作的。

我也在CSS中尝试过:

overflow: hidden;

这确实隐藏了滚动条,但我不能再滚动了。

有没有一种方法可以删除滚动条,同时仍然可以滚动整个页面?

请只使用CSS或HTML。


当前回答

我加了这个,它对我有用

-ms溢出样式:无;/*IE和Edge*/滚动条宽度:无;/*Firefox浏览器*/

裁判:https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp

其他回答

这个答案不包括代码,所以下面是第页的解决方案:

根据页面的说法,这种方法不需要提前知道滚动条的宽度就可以工作,而且解决方案也适用于所有浏览器,可以在这里看到。

好的是,您不必使用填充或宽度差异来隐藏滚动条。

这也是缩放安全的。填充/宽度解决方案在缩放到最小值时显示滚动条。

Firefox修复程序:http://jsbin.com/mugiqoveko/1/edit?output

要素.外部容器{宽度:200px;高度:200px;}.外部容器{边框:5px纯紫色;位置:相对;溢出:隐藏;}.内部容器{位置:绝对;左:0;overflow-x:隐藏;overflow-y:滚动;右填充:150px;}.内部容器::-webkit滚动条{显示:无;}<div class=“outer container”><div class=“内部容器”><div class=“element”>Lorem ipsum dolor坐amet,consectetur adipiscing elit。整数车辆quam nibh,eu tristique tellus dignissim quis。整体调味品ultrices elit ut mattis。Praesent rhoncus tortor metus,nec pellentesque enim mattis nec。Nulla vitae turpis utdui consectetur pellentesque quis vel est。Curabitur rutrum,mauris ut mollis lobortis,sem est congue lectus,ut sodales nunc leo a libero。克雷斯·萨皮恩(Cras quis sapien)在米弗利利亚·坦普斯(mi frigilla tempus)调味品奎斯·韦利特(quis velit)中。Aliquam和Aliquam arcu。Morbi三体阿利奎姆·鲁特鲁姆(aliquam rutrum)。杜伊斯·廷西杜特(Duis tincidunt)、兽人(orci suscipit cursus interstie)、普鲁斯·尼西·法雷特拉(purus nisi phareta dui)、米的迪格尼斯·菲利斯·图比斯(tempor dignissim felis turpis)。Vestibulum turpis neque,调味品,调戏维尔·茹斯托。不要骚扰我,不要骚扰我。还有一个巨大的sem。Quisque id magna ultrices,lobortis dui eget,pretium libero。在未成年人之前,库拉比特人(Curabitur aliquam)。</div></div></div>

您可以使用下面的代码隐藏滚动条,但仍可以滚动:

.element::-webkit-scrollbar { 
    width: 0 !important 
}

这适用于我的跨浏览器。然而,这不会在移动浏览器上隐藏本机滚动条。

在SCSS中

.hide-native-scrollbar {
  scrollbar-width: none; /* Firefox 64 */
  -ms-overflow-style: none; /* Internet Explorer 11 */
  &::-webkit-scrollbar { /** WebKit */
    display: none;
  }
}

在CSS中

.hide-native-scrollbar {
  scrollbar-width: none; /* Firefox 64 */
  -ms-overflow-style: none; /* Internet Explorer 11 */
}
.hide-native-scrollbar::-webkit-scrollbar { /** WebKit */
  display: none;
}

另一种黑客方法是执行overflow-y:hidden,然后手动滚动元素,如下所示:

function detectMouseWheelDirection(e) {
  var delta = null, direction = false;
  if (!e) { // If the event is not provided, we get it from the window object
    e = window.event;
  }
  if (e.wheelDelta) { // Will work in most cases
    delta = e.wheelDelta / 60;
  } else if (e.detail) { // Fallback for Firefox
    delta = -e.detail / 2;
  }
  if (delta !== null) {
    direction = delta > 0 ? -200 : 200;
  }
  return direction;
}

if (element.addEventListener) {
  element.addEventListener('DOMMouseScroll', function(e) {
    element.scrollBy({
      top: detectMouseWheelDirection(e),
      left: 0,
      behavior: 'smooth'
    });
  });
}

deepmikoto的博客中有一篇关于如何检测和处理onmousewheel事件的精彩文章。这可能对你有用,但绝对不是一个优雅的解决方案。

这对我有用:

scroll-content {
    overflow-x: hidden;
    overflow-y: scroll;
}

scroll-content::-webkit-scrollbar {
    width: 0;
}