提问者:小点点

隐藏滚动条并制作自定义滚动条


所以我想做一个像https://www.guillaumetomasi.com/这样的页面。我怎样才能隐藏滚动条并在页面中做一个像这样的自定义的。


共3个答案

匿名用户

使用诸如overflow-x:hiddedoverflow-y:hidded之类的CSS属性,可以隐藏滚动条。

定制滚动条和滚动过程由Javascript通过和事件控制。

匿名用户

事情很简单,他们根本没有使用任何滚动,但是你感觉到的是那些幻灯片的修改滚动实际上是一个由JavaScript功能构建的幻灯片放映。 这些侧面幻灯片是当今的潮流,给你一种伪滚动的感觉。 如果你问如何在网页中实现幻灯片显示,而不是滚动,那会更好。。。

匿名用户

滚动条可以用css::-webkit-scrollbar{width:0px;}隐藏。自定义滚动条是用JavaScript制作的。 下面是一个如何实现的示例:

window.addEventListener("scroll", function() {
  var section1 = document.getElementById("section1");
  var section2 = document.getElementById("section2");
  var section3 = document.getElementById("section3");
  
  var indicator = document.getElementById("scroll-indicator");
  if (window.scrollY < section2.offsetTop ) { // If scroll height is above section 2
      indicator.innerText = "1"
  }
  if (window.scrollY > (section1.offsetTop + section1.offsetHeight)) { // If scrolled past section 1
      indicator.innerText = "2"
  }
  if (window.scrollY > (section2.offsetTop + section2.offsetHeight)) {// If scrolled past section 2
      indicator.innerText = "3"
  }
});
p {
  position: fixed;
  right: 15%;
  top: 50%;
  color: black;
  font-size: 24px;
  font-family: arial;
}

::-webkit-scrollbar {
    width: 0px; /*This removes the scroll bar*/
}
<div id="section1" style="height: 500px; background-color: lightblue">Scroll Down</div>
<div id="section2" style="height: 500px; background-color: pink">Keep scrolling</div>
<div id="section3" style="height: 500px; background-color: Khaki">Almost there</div>

<p id="scroll-indicator">1</p>