The reason your code only works in Chrome is because of your use of the -webkit-scrollbar
property. This property specifically targets browsers like Chrome and Safari that are built on the Webkit rendering engine. If you want to hide scrollbars, it's recommended to use the overflow
property instead. Here's a CSS solution:
body {
overflow: hidden;
}
If you prefer to achieve this using jQuery, you can dynamically add the overflow property like this:
$("body").css("overflow", "hidden");
Keep in mind that you don't have to apply this property to the entire body - any valid selector will work!
If you're looking to hide the scrollbar while still allowing scrolling, you can try a workaround by adding an inner container with overflow: auto
and some right padding. This will push the scrollbar out of view effectively hiding it.
You can see this technique in action in this fiddle: http://jsfiddle.net/zjfdvmLx/
One downside of this method is that it may not be fully compatible across all browsers. Different browsers may render scrollbars differently, so you might need to adjust the value (such as the 15px
used in the fiddle) based on your browser's scrollbar width.
For more information, check out this answer.