I tried setting the visibility of the scrollbar thumb via jquery like so:
$('-webkit-scrollbar-thumb').css('visibility', 'hidden')
But it didn't actually do anything. Here's my CSS Definition:
::-webkit-scrollbar-thumb {
-webkit-border-radius: 10px;
background: rgba(150, 150, 150, 0.8);
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
border-radius: 2;
margin: 5px;
}
I can't disable scrolling by hiding the overflow because I still need scrolling enabled, I just need to hide the scrollbar thumb through javascript.
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.
Projects In JavaScript & JQuery To toggle a div visibility in jQuery, use the toggle() method. It checks the div element for visibility i.e. the show() method if div is hidden. And hide() id the div element is visible. This eventually creates a toggle effect.
The :visible selector in jQuery is used to select every element which is currently visible. It works upon the visible elements. The elements that are consuming space in the document are considered visible elements. The height and width of visible elements are larger than 0.
version added: 1.0jQuery( ":visible" )Elements are considered visible if they consume space in the document. Visible elements have a width or height that is greater than zero. Elements with visibility: hidden or opacity: 0 are considered visible, since they still consume space in the layout.
You cannot query html pseudo-elements with jQuery.
You need to use a workaround for this kind of rules: specify 2 different rules in the css :
/*normal*/
::-webkit-scrollbar-thumb {
/*...*/
}
/*hidden*/
.hide-scrollbar ::-webkit-scrollbar-thumb{
visibility : hidden;
}
And then enable/disable them simply by adding/removing classes from the root node (html) :
$('html').addClass('hide-scrollbar');
// now the second rule is active and the scrollbar is hidden
You can use pure JavaScript to do this:
document.styleSheets[2].addRule("::-webkit-scrollbar-thumb", "visibility: hidden;");
To be able to select your right stylesheet, give it a title (using the title
attribute in your link
or style
tag), and then do:
for(var i = 0; i < document.styleSheets.length; i ++) {
var cursheet = document.styleSheets[i];
if(cursheet.title == 'mystylesheet') {
cursheet.addRule("::-webkit-scrollbar-thumb", "visibility: hidden;");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With