javascript - 如何仅在滚动时显示滚动条
问题描述
我使用完美滚动条https://github.com/mdbootstrap/perfect-scrollbar自定义滚动条。只有当您将鼠标悬停在容器上时,滚动条才可见。
如何仅在滚动事件上显示栏并在滚动结束时隐藏它?
解决方案
您可以尝试使用 javascriptonscroll()
函数。试试这样的 -
<html>
<body onscroll="bodyScroll();">
<script language="javascript">
var scrollTimer = -1;
function bodyScroll() {
document.body.style.backgroundColor = "white";
if (scrollTimer != -1)
clearTimeout(scrollTimer);
scrollTimer = window.setTimeout("scrollFinished()", 500);
}
function scrollFinished() {
document.body.style.backgroundColor = "red";
}
</script>
<div style="height:2000px;">
Scroll the page down. The page will turn red when the scrolling has finished.
</div>
</body>
</html>
此代码来自另一个堆栈问题- 我如何知道何时停止滚动?
链接到js 中的onscroll()
事件 - https://www.w3schools.com/jsref/event_onscroll.asp
推荐阅读
- audio - 音频比特率变化对频谱图的影响
- android - 好像有错误,没有
- r - 尝试在 R 中使用单独()函数时在 UseMethod 中出现错误
- javascript - 即使使用空括号,如何修复 React 的 useEffect 无限循环?
- javascript - JavaScript 以编程方式检查是否正在使用相机
- html - 如何获取图像高度并将该高度赋予图像 div 以使其响应
- mysql - MYSQL - 无法添加外键约束,但为什么呢?
- asp.net-mvc - Razor 默认使用 SignalR 吗?
- azure - Azure 逻辑应用 - 如何跨多个资源组共享集成帐户
- reactjs - 找不到所需的文件。- 将 TypeScript 添加到 React 项目