39

Possible Duplicate:
How to disable browser or element scrollbar, but allow scrolling with wheel or arrow keys?

I want to know if it is possible to hide the scrollbar, while scrolling is still enabled with mouse/keyboard.

I tried to use CSS: overflow: hidden;. The effect is scrollbar disabled and scrolling disabled.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Arthur
  • 851
  • 3
  • 11
  • 24

3 Answers3

45

For future reference there is also a solution without jQuery - just have the wrapper div style contain overflow:hidden and use this JavaScript two-liner:

// get the width of the textarea minus scrollbar
var textareaWidth = document.getElementById("textarea").scrollWidth;

// width of our wrapper equals width of the inner part of the textarea
document.getElementById("wrapper").style.width = textareaWidth + "px";

See demo or complete HOWTO.

Update: you can use the same principle to create scrollable div without scrollbar: demo.

Geeky Guy
  • 8,658
  • 4
  • 38
  • 60
honzzz
  • 723
  • 1
  • 15
  • 25
  • 5
    Nice, but what's about browser and mobile compatibility for this ? – cocoa coder Nov 29 '12 at 13:12
  • 1
    @cocoacoder you could always TRY it in different browsers and mobile if you're wondering... I tested on iOS and IE9 and it works fine. There's nothing too hacky about this approach, so it should be pretty cross-compatible. As long as the platform supports the scrollWidth property it will work fine. – Gavin Sep 13 '13 at 06:23
  • it seems all browsers around the world supports it: http://www.w3schools.com/jsref/prop_element_scrollwidth.asp – Mahdi Jazini Dec 25 '16 at 12:53
6

There is a jQuery plugin called Scrollable that does what you want.

Mathias Rechtzigel
  • 3,450
  • 1
  • 14
  • 36
Peter Örneholm
  • 2,831
  • 18
  • 24
0

Not natively, but I suppose you could implement your own scrolling mechanism by using Javascript to capture certain keystrokes and re-position the container element accordingly with CSS. It's going to be ugly, though!

slugster
  • 47,434
  • 13
  • 92
  • 138
Josh Stodola
  • 77,975
  • 43
  • 178
  • 222