Hide scroll bar, but while still being able to scroll

前端 未结 30 3395
悲哀的现实
悲哀的现实 2020-11-21 04:22

I want to be able to scroll through the whole page, but without the scrollbar being shown.

In Google Chrome it\'s:

::-webkit-scrollbar {
    display:         


        
相关标签:
30条回答
  • 2020-11-21 05:04

    On modern browsers you can use wheel event:

    // Content is the element you want to apply the wheel scroll effect to
    content.addEventListener('wheel', function(e) {
        const step = 100; // How many pixels to scroll
    
        if (e.deltaY > 0) // Scroll down
            content.scrollTop += step;
        else // Scroll up
            content.scrollTop -= step;
    });
    
    0 讨论(0)
  • 2020-11-21 05:05

    I happen to try the above solutions in my project and for some reason I was not able to hide the scroll bar due to div positioning. Hence, I decided to hide the scroll bar by introducing a div that covers it superficially. Example below is for a horizontal scroll bar:

    <div id="container">
      <div id="content">
         My content that could overflow horizontally
      </div>
      <div id="scroll-cover">
         &nbsp; 
      </div>
    </div>
    

    Corresponding CSS is as follows:

    #container{
       width: 100%;
       height: 100%;
       overflow: hidden;
       position: relative;
    }
    
    #content{
      width: 100%;
      height: 100%;
      overflow-x: scroll;
    }
    #scroll-cover{
      width: 100%;
      height: 20px;
      position: absolute;
      bottom: 0;
      background-color: #fff; /*change this to match color of page*/
    }
    
    0 讨论(0)
  • 2020-11-21 05:05

    You can use the code below to hide the scroll bar, but while still being able to scroll:

    .element::-webkit-scrollbar { 
        width: 0 !important 
    }
    
    0 讨论(0)
  • 2020-11-21 05:06

    Just use following three lines and your problem will be solved:

    #liaddshapes::-webkit-scrollbar {
        width: 0 !important;
    }
    

    Where liaddshapes is the name of the div where scroll is coming.

    0 讨论(0)
  • 2020-11-21 05:06

    To hide scroll bars for elements with overflowing content use.

    .div{
    
      scrollbar-width: none; /* The most elegant way for Firefox */
    
    }    
    
    0 讨论(0)
  • 2020-11-21 05:06

    I just wanted to share a combined snippet for hiding the scrollbar that I use when developing. It is a collection of several snippets found on the Internet that works for me:

    .container {
        overflow-x: scroll; /* For horiz. scroll, otherwise overflow-y: scroll; */
    
        -ms-overflow-style: none;
        overflow: -moz-scrollbars-none;
        scrollbar-width: none;
    }
    
    
    .container::-webkit-scrollbar {
        display: none;  /* Safari and Chrome */
    }
    
    0 讨论(0)
提交回复
热议问题