Re: detect if scrollbars are visible inside a div
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: detect if scrollbars are visible inside a div

From: Gérard Talbot <newsblahgroup@gtalbot.org>
Date: Wed Aug 17 2005 - 06:41:10 CEST

andrew.neale@totalise.co.uk wrote :
> I think I have sorted the problem
>
> if (document.getElementById('divID').scrollHeight >
> document.getElementById('divID').clientHeight)
> {
> //a scroll bar is present

Correction: a vertical scrollbar is rendered.

> }
> else
> {
> //a scroll bar is NOT present

Correction: a vertical scrollbar is not rendered.

> }
>
> can anyone see any problems with this?
>

You need to do the same for clientWidth and scrollWidth to detect the
presence of an horizontal scrollbar.
Finally, your code should get to know what is the current/computed css
overflow value because the client vs scroll comparison is equal for
overflow: scroll when there is nothing to scroll actually. So, the
scrollbar is present and rendered but your code fails to detect this for
both scrollbars.

Gérard

--
remove blah to email me
Received on Tue Oct 18 03:09:50 2005