Log in

View Full Version : Scroll without a scrollbar



Rain Lover
12-06-2012, 08:30 PM
Sample form:


<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
* {font:13px arial; color:white;}
body {background:black;}
label {display:inline-block; width:50px;}
input, textarea {margin:0; border:1px solid red; padding:0; background:green;}
textarea {width:300px; height:100px;}
</style>
</head>
<body>
<form action="#">
<div><label for="entry_0">Name</label><input type="text" id="entry_0"></div>
<div><label for="entry_1">Email</label><input type="text" id="entry_1"></div>
<div><label for="entry_2">URL</label><input type="text" id="entry_2"></div>
<div id="parent"><textarea id="entry_3"></textarea></div>
<div><input type="submit" value="Submit"></div>
</form>
</body>
</html>

I'd like to remove/hide the textarea scrollbar as it doesn't match my form style. I know I can use jQuery plugins to style the scrollbar, but they don't work reliably across different browsers/systems.
To hide the scrollbar I can use textarea {width:300px; height:100px; overflow:hidden;}, but it completely stops Firefox scrolling through mouse and keyboard.
I also tried the following workaround:


#parent {width:284px; height:102px; overflow:hidden;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}

It should work accurately if I add some script to calculate the parent division width:


var textareaWidth = document.getElementById('entry_3').scrollWidth;
document.getElementById('parent').style.width = textareaWidth + 'px';

But anyhow the above approach doesn't seem to work in Chrome/Safari:
Demo: http://jsfiddle.net/RainLover/snTaP/

Open the above demo in Chrome/Safari >> insert some text into the textarea >> highlight/select a line and drag your mouse to the right and you'll see the scrollbar. Or use the keyboard keys Page Up and Page Down.

Any corrections or other solutions?

LearningCoder
12-06-2012, 09:23 PM
Try explicitly declaring the rows and cols for the textarea:


<textarea id="entry_3" rows="5" cols="30"></textarea>


When I added it to your code on that page and pressed Run, typed some text in, it didn't show a scrollbar anymore.

Kind regards,

Lc.

Rain Lover
12-07-2012, 08:30 AM
Try explicitly declaring the rows and cols for the textarea:


<textarea id="entry_3" rows="5" cols="30"></textarea>


When I added it to your code on that page and pressed Run, typed some text in, it didn't show a scrollbar anymore.

Kind regards,

Lc.

It makes no changes. Thanks anyway!

LearningCoder
12-07-2012, 09:11 AM
That's strange because I tried it on your site example and also tested it locally and it worked both times.

Regards,

Lc.

bernie1227
12-07-2012, 09:41 AM
This may assist:
http://stackoverflow.com/questions/3293650/hide-scrollbar-while-still-able-to-scroll-with-mouse-keyboard

Rain Lover
12-07-2012, 11:59 AM
This may assist:
http://stackoverflow.com/questions/3293650/hide-scrollbar-while-still-able-to-scroll-with-mouse-keyboard

I've already seen that. It doesn't help.
Thanks all the same!

bernie1227
12-08-2012, 01:53 AM
But anyhow the above approach doesn't seem to work in Chrome/Safari:
Demo: http://jsfiddle.net/RainLover/snTaP/

Open the above demo in Chrome/Safari >> insert some text into the textarea >> highlight/select a line and drag your mouse to the right and you'll see the scrollbar. Or use the keyboard keys Page Up and Page Down.

It's working fine for me in both Chrome and Safari when I highlight and drag or use pg up and pg down keys.

Rain Lover
12-08-2012, 02:47 AM
It's working fine for me in both Chrome and Safari when I highlight and drag or use pg up and pg down keys.

You mean in Chrome/Safari the scrollbar doesn't appear when you highlight/select a line and drag your mouse to the right or use the keyboard keys Page Up and Page Down?

bernie1227
12-08-2012, 02:49 AM
That is correct.

Rain Lover
12-08-2012, 05:33 AM
That is correct.

That means scrolling behavior differs from system to system even in the same browser. Weird! I tried it on two desktop computers running Windows XP and in the latest versions of Chrome & Safari.

bernie1227
12-08-2012, 05:44 AM
With your jsfiddle, I can't get the scrollbar to appear in any browser, it appears to be working as you want it.

I'm running the latest versions of all browsers on OS X Mountain Lion.

Rain Lover
12-08-2012, 05:58 AM
With your jsfiddle, I can't get the scrollbar to appear in any browser, it appears to be working as you want it.

I'm running the latest versions of all browsers on OS X Mountain Lion.

Thanks for checking and letting me know! :)