Deactivate or remove the scrollbar on HTML

前端 未结 5 811
温柔的废话
温柔的废话 2020-12-14 02:04

I want to de-activate or remove the vertical scrollbar in an HTML page.
How to do that ?

Thanks.

相关标签:
5条回答
  • 2020-12-14 02:21

    If you really need it...

    html { overflow-y: hidden; }
    
    0 讨论(0)
  • 2020-12-14 02:23

    Meder Omuraliev suggested to use an event handler and set scrollTo(0,0). This is an example for Wassim-azirar. Bringing it all together, I assume this is the final solution.

    We have 3 problems: the scrollbar, scrolling with mouse, and keyboard. This hides the scrollbar:

           html, body{overflow:hidden;}
    

    Unfortunally, you can still scroll with the keyboard: To prevent this, we can:

        function keydownHandler(e) {
    var evt = e ? e:event;
      var keyCode = evt.keyCode;
    
      if (keyCode==38 || keyCode==39 || keyCode==40 || keyCode==37){ //arrow keys
    e.preventDefault()
    scrollTo(0,0);
    }
    }
    
    document.onkeydown=keydownHandler;
    

    The scrolling with the mouse just naturally doesn't work after this code, so we have prevented the scrolling.

    For example: https://jsfiddle.net/aL7pes70/1/

    0 讨论(0)
  • 2020-12-14 02:24

    put this code in your html header:

    <style type="text/css">
    html {
            overflow: auto;
    }
    </style>
    
    0 讨论(0)
  • 2020-12-14 02:30

    This makes it so if before there was a scrollbar then it makes it so the scrollbar has a display of none so you can't see it anymore. You can replace html to body or a class or ID. Hope it works for you :)

    html::-webkit-scrollbar {
        display: none;
    }
    
    0 讨论(0)
  • 2020-12-14 02:36

    What I would try in this case is put this in the stylesheet

    html, body{overflow:hidden;}
    

    this way one disables the scrollbar, and as a cumulative effect they disable scrolling with the keyboard

    0 讨论(0)
提交回复
热议问题