简体   繁体   English

如何在静态时隐藏 Chromium 中的滚动条,但在滚动时显示?

[英]How to hide scrollbar in Chromium when static , but show when scrolling?

Is it possible to hide the scrollbar when static, but show when scrolling?是否可以在静态时隐藏滚动条,但在滚动时显示?

I tried the following css based on this post , but the scrollbar doesn't show up during scrolling.我根据这篇文章尝试了以下 css,但滚动期间没有显示滚动条。

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

There is another post achieving similar feature on Firefox, but not Chromium.还有另一篇文章在 Firefox 上实现了类似的功能,但不是 Chromium。

It would be best if this feature can be achieved by css.最好能通过css实现这个功能。

Set up a timer to show the scrollbar, and on scroll event reset the timer and show the scrollbar:设置一个计时器来显示滚动条,并在滚动事件中重置计时器并显示滚动条:

var el = document.body; // you can use the following code on any element
var showScrollbarTimeout = 0; // track the timeout function so that we can reset it later

function hideScroll () { el.style.overflow = "hidden"; }
function showScroll () { el.style.overflow = "visible"; }

function hideLater () { showScrollbarTimeout = setTimeout(hideScroll, 1000); }

hideLater();

el.onscroll = function () {
    clearTimeout(showScrollbarTimeout);
    showScroll();
    hideLater();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM