简体   繁体   English

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

[英]Hiding scrollbar and making custom scrollbar

So I wanted to make a page like https://www.guillaumetomasi.com/ .How can I hide the scrollbar and make a custom one like that in the page.所以我想制作一个像https://www.guillaumetomasi.com/这样的页面。如何隐藏滚动条并在页面中制作一个这样的自定义页面。

With CSS attributes like overflow-x: hidden and overflow-y: hidden you can hide scrollbars.使用 CSS 属性如overflow-x: hiddenoverflow-y: hidden你可以隐藏滚动条。

The custom scrollbar and the scrolling proccess is controlled by Javascript via and events.自定义滚动条和滚动过程由 Javascript 通过和事件控制。

The thing is simple and that's, they are not using any scrolling at all, but what you feel is a modified scroll for those slides is actually a slideshow built by JavaScript functionalities.事情很简单,他们根本不使用任何滚动,但您感觉这些幻灯片的修改滚动实际上是由 JavaScript 功能构建的幻灯片。 These side slideshow are nowadays in trend and gives you a feel of pseudo scroll.这些侧面幻灯片现在很流行,给你一种伪滚动的感觉。 It will be better if you would ask how to achieve that slideshow in a web page instead of that scrolling...如果您问如何在 web 页面而不是滚动页面中实现该幻灯片放映会更好...

The scroll bar can be hidden with css ::-webkit-scrollbar {width: 0px;} The custom scroll bar is made with javascript.滚动条可以用 css ::-webkit-scrollbar {width: 0px;}隐藏滚动条 自定义滚动条是用 javascript 制作的。 Here's an example of how it could be done:这是如何完成的示例:

 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>

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

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