28

I know you can define overflow:hidden; on the body of the HTML to remove the scrollbar, but I would like to still be able to scroll with the arrows or scroll wheel on a mouse.

Thanks in advance for any help.

Edit: Thanks for all the advice about on hover scrollbars and custom bars. Also thank you for all concerns about impacting users experience by removing the scrollbars. I shall elaborate a little more so you explain where I am coming from.

I have a circular page (if you scroll with a scroll wheel or arrow button, when it reaches the bottom it resets to the top of the page and starts again). A never ending loop. A scrollbar impacts on this as a bar is limited and when it reaches the bottom and resets to the top the users mouse is still at the bottom of the page meaning when they move it there is some flickering between the top and bottom of the page.

I plan to remove the scroll bar and replace it with arrow buttons at the top and the bottom of the window. This is why I would like to remove the scrollbar completely but leave the scrolling functionality.

Somk
  • 11,869
  • 32
  • 97
  • 143
  • 10
    Sad day for people without mouse wheels :( – SpaceFace Nov 09 '12 at 23:10
  • 2
    @Prupel I agree, but on the other hand, who uses mouse without wheel these days? – MilkyWayJoe Nov 09 '12 at 23:14
  • 5
    @MilkyWayJoe - Laptop users who only have a trackpad? The bigger problem with this idea is not how do users with the wrong equipment (or some physical disability) make it work, but how do _any_ users even know that that content _can_ scroll? – nnnnnn Nov 09 '12 at 23:16
  • 4
    How would you feel about keeping the scrollbars BUT on mouseover only? I personally find it a good mix between looks and functionality. – Iain_b Nov 09 '12 at 23:16
  • 1
    @Iain_b `#foo { overflow: hidden; } #foo:hover { overflow: auto; }`, interesting. – Dai Nov 09 '12 at 23:19
  • @Dai Yeah, I think this is a good way of dealing with scrollbars - they appear when they're useful and not otherwise. There are plugins you can get to make scrollbars more elegant, too. – Iain_b Nov 09 '12 at 23:26
  • I am planning on placing an up and down arrow respectively on the page. The reason for removing the scrollbar is because the page is circular with a little javascript. Meaning using a scroll wheel or arrow button it is seemless, but a scroll bar is limited. Compared to a button that will work continually – Somk Nov 09 '12 at 23:48

3 Answers3

25

There is a library for jQuery named jscrollpane http://jscrollpane.kelvinluck.com/#examples that can modify very much.

But if you only want to hide the bar, you can also push this scrollbar out of view: http://jsfiddle.net/H27BK/

<div id="content">
    <div id="scrollable"> ... ... ... </div>
</div>

with CSS

#content {
    position: relative;
    width: 200px;
    height: 150px;
    border: 1px solid black;
    overflow: hidden;
}
#scrollable {
   height: 150px;   
   width: 218px; /* #content.width + 18px */
   overflow-y: scroll;    
}

This all based up on a bar-width of 18 pixel.


So we can do some javascript scrollbar width detection script or simply add another div that we put in front of the scrollable div.

http://jsfiddle.net/uNzEz/

HTML is now:

<div id="content">
<div id="scrollable">
<div id="txt"> ... ... ...
</div></div></div>

with CSS like:

#content {
    position: relative;
    width: 200px;
    height: 150px;
    border: 1px solid black;
    overflow: hidden;
}
#scrollable {
   height: 150px;   
   width: 240px; /* the bar-width can be theoretical 240px - 200px = 40px */
   overflow-y: scroll;    
}
#txt {
    width: 200px;
}

Varon
  • 3,736
  • 21
  • 21
1

Ok, new answer. I just developed a little trick to do so, mixed with jQuery.

Create a wrapper div inside the body, with the following css.

body { overflow: hidden; }

#wrapper { overflow: auto; }

Then, simply set their respective heights:

$("body").height($(window).height());
$("#wrapper").height($("#text").height());

Demo


To support for resizes

$(window).trigger('scroll');

$(window).scroll(function() {
    $("body").height($(window).height());
    $("#wrapper").height($("#text").height());    
});

Demo

Starx
  • 77,474
  • 47
  • 185
  • 261
  • 1
    I need to define the body as something big like 4000px but remove the scroll bar. – Somk Nov 09 '12 at 23:13
  • 3
    this doesn't work for me and doesn't make sense at all – Sotiris Nov 09 '12 at 23:13
  • 1
    This doesn't work for me - nothing happens with keyboard or scroll wheel (after clicking on the body to be sure it has focus). Changing it to `overflow: scroll;` and it works, but then the scrollbars appear. – nnnnnn Nov 09 '12 at 23:15
  • @nnnnnn, I misunderstood the question a bit and previous solution will work on fixed sizez. Anyways new answer check it out. – Starx Nov 09 '12 at 23:49
  • Thank you for your time but this does not support the up and down buttons nor a mouse track pad on a laptop – Somk Nov 09 '12 at 23:55
  • @Max, That's funny, I am build that fiddle using a laptop. – Starx Nov 10 '12 at 02:46
0

You can try using one of the jQuery scrollbar plugins, they allow for customized css design...

You can simply choose to design your scrollbar to be invisible, but mouse functionality will remain...

my personal favorite is malihu's, just make sure to use it's mousewheel extension.

EDIT:

Perhaps after you check out how custom designed scrollbars look, you can rethink showing scrollbars. they are, after all, useful and instructive.

Rodik
  • 4,054
  • 26
  • 49
  • 1
    I have yet to see a JS "custom scrolling" solution that wasn't terrible (jerky, slow to scroll, etc.). Why reinvent the wheel? – cimmanon Nov 09 '12 at 23:28
  • well you probably haven't seen this certain plugin yet, secondly, this fits perfectly into the asker's case. – Rodik Nov 09 '12 at 23:29
  • http://manos.malihu.gr/tuts/custom-scrollbar-plugin/tabs_temp_demo.html ? Actually, I have, and it is just as bad as every other one I've ever seen. – cimmanon Nov 09 '12 at 23:31
  • I don't think this deserves to be down-voted. As I said above I think scrollbars should show on hover but once they do I think that the suggested plugin is a good option. – Iain_b Nov 09 '12 at 23:33
  • let's just agree to call it a downside of my idea, along side with it being too complex for such a mundane task, and that it's another dependency. – Rodik Nov 09 '12 at 23:33
  • The inertial scrolling is bad but it can (should) be disabled. – Iain_b Nov 09 '12 at 23:35
  • Also, cimmanon, this plugin is now out in a 2.0 version. you should check it out, it might have become better. – Rodik Nov 09 '12 at 23:35
  • Although this is very old now, I'd like to point out a JS library for scrolling that in my experience is actually brilliant, and is useful for other use-cases like better scrolling for mobile: [FTScroller](https://github.com/ftlabs/ftscroller) – gdgr Jun 12 '15 at 11:28
  • Problem with malihu... if you are using a video or audio tag, it sometimes prevents auto-play. – James Walker Dec 31 '16 at 02:26