views:

64

answers:

3

whenever the page's height is larger than the web browser window a scrollbar will appear to the right so you can scroll down/up in your page.

could scrollbar be displayed with javascript/jquery all the time even if there is no need for it? (has to do with a layout issue i've got)

+2  A: 

If you give the appropriate container element the style `overflow: scroll' then it'll have scrollbars. You can do that with jQuery if you like:

$('#containerId').css({overflow: 'scroll'});

Or of course you can do it in a CSS file, or even right on the element itself. You'll have to figure out which element to do that to; post some code if you need advice.

Pointy
is it possible to have a jquery handler that "senses" whenever the scrollbar is shown? eg. alerting me everytime its shown?
weng
Hmm well if you set `overflow: scroll` it'll be there all the time. I don't know of any standard browser event that is fired on "scrollization". To me this sounds like a situation in need of a fresh approach.
Pointy
it was better to show it all the time...in that way my layout issue got solved
weng
+2  A: 

You can do that even without javascript, it is a CSS property:

overflow: scroll

But this will also always show a scrollbar at the bottom. Afaik you cannot avoid this.
It might be that this confuses the user somehow as normally he is not used to the fact that a scrollbar is shown even if he cannot scroll.
Before you use this solution, you should try to fix your layout issue.

Felix Kling
is there really no way to hide the bottom horizontal scrollbar?
weng
@noname: As I said, I don't know of a way (and I don't think that one exists).
Felix Kling
there was a way..overflow-x:hidden =)
weng
@noname: Cool, seems to be new in CSS3. Lucky you ;)
Felix Kling
so all browsers are using css3 at the moment?
weng
@noname: The specification of CSS3 is still in progess, but some properties are already supported by newer browsers. Search for it, you will find which ones are supported by which browser. For older browsers `overflow-x` might not work though.
Felix Kling
+1  A: 

Don't need javascript. Just add the css

body{ 
    overflow: scroll;
}
PetersenDidIt