views:

409

answers:

3

Hi,

For an overlay i need to know the height of a vertical scrollbar.

What can i do to get this value? And is the height the same in FireFox and Internet Explorer?

Thnx

A: 

I expect you could do some magic with JavaScript (might want to add the JavaScript tag to this question), involving the window size (if that's available) and the viewport size. Also, I very much doubt that the sizes are similar in all the different browsers, and I expect there's even more trouble when theming or resolution independent OSi come into play.

elliottcable
A: 

I recommend you to use a JavaScript framework like jQuery so you don’t have to reinvent the wheel.

Gumbo
+1  A: 

What can i do to get this value?

function getScrollSizes() { // call after document is finished loading
    var el= document.createElement('div');
    el.style.display= 'hidden';
    el.style.overflow= 'scroll';
    document.body.appendChild(el);
    var w= el.offsetWidth-el.clientWidth;
    var h= el.offsetHeight-el.clientHeight;
    document.body.removeChild(el);
    return new Array(w, h);
}

And is the height the same in FireFox and Internet Explorer?

No. The height isn't even the same in Internet Explorer and Internet Explorer. Variables such as dpi settings, theme and OS version can also affect it.

bobince
Thnx, this works fine :)
Martijn