-1

I can hide the scrollbar in Chrome with:

# app.css loaded in <head>
html ::-webkit-scrollbar {
  display: none;
}

Now I want to manually hide the scrollbar, so I try to run the following with jQuery:

$("html ::-webkit-scrollbar").css("display", "none")

However, the scrollbar stays visible during scrolling.

How can I manually hide/show the scrollbar?

3
  • Does this answer your question? webkit scrollbar using jQuery.css() method Commented Feb 13, 2020 at 21:39
  • Thanks for sharing. Looks like there is no way to work with pseudo-elements directly with jquery. The proposed solution $('html').addClass('hide-scrolling') (adapted from answer) doesn't work for me though. Scrollbar stays visible. Is this how it's supposed to work? Commented Feb 13, 2020 at 21:56
  • 1
    Please check my answer with the working example Commented Feb 13, 2020 at 22:07

1 Answer 1

1

According to this answer: webkit scrollbar using jQuery.css() method you can't work with pseudo-elements using JQuery but you can use a class to 'hack' it:

$('html').addClass('hide-scrolling')
.hide-scrolling::-webkit-scrollbar {
       width: 30px;
}
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.