javascript hide scrollbar but allow scrolling code example

Example 1: css hide scrollbar but allow scroll

html {
  overflow:   scroll;
}
::-webkit-scrollbar {
    width: 0px;
    background: transparent; /* make scrollbar transparent */
}

Example 2: javascript hide scrollbar

// You can hide the document scrollbar with this...
document.body.style.overflow = 'hidden';
//...and unhide it with this:
document.body.style.overflow = 'visible';

// Or switch between them:
booleanCondition
  ? document.body.style.overflow = 'hidden'
  : document.body.style.overflow = 'visible';

Example 3: javascript hide scrollbar

function HideScrollbar() {
  var style = document.createElement("style");
  style.innerHTML = `body::-webkit-scrollbar {display: none;}`;
  document.head.appendChild(style);
}

Tags:

Css Example