我使用 Perfect-scrollbar https://github.com/mdbootstrap/perfect-scrollbar自定義滾動條。滾動條僅在您將滑鼠懸停在容器上時可見。
如何僅在滾動事件上顯示欄并在滾動結束時隱藏它?
uj5u.com熱心網友回復:
您可以嘗試使用 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>
此代碼來自另一個堆疊問題- 我如何知道何時停止滾動?
鏈接到onscroll()js 中的事件- https://www.w3schools.com/jsref/event_onscroll.asp
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/346282.html
標籤:javascript html css 自定义滚动 完美滚动条
