473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

detect if scrollbars are visible inside a div

Hello,

I have a div that has an overflow set to auto. I would like to know if
the scrollbars are visible in javascript.

Any help is appreciated.

Thanks

Aug 11 '05 #1
3 17275
I think I have sorted the problem

if (document.getElementById('divID').scrollHeight >
document.getElementById('divID').clientHeight)
{
//a scroll bar is present
}
else
{
//a scroll bar is NOT present
}

can anyone see any problems with this?

Aug 11 '05 #2
an**********@totalise.co.uk wrote:
I think I have sorted the problem

if (document.getElementById('divID').scrollHeight >
document.getElementById('divID').clientHeight) .... can anyone see any problems with this?


The below code fails to detect a horizontal scroll bar on Firefox

<div id=div1 style="border:1px solid
red;width:120px;height:50px;overflow:auto">
There_once_was_a_boy_from_nod_Who_carried_a_lot_of _sod</div><br>

<div id=div2 style="border:1px solid
red;width:120px;height:50px;overflow:auto">
There once was a boy from nod Who carried a lot of sod</div>

<script type='text/javascript'>
function scrollDetect(elemId) {
var elem = document.getElementById(elemId);
if (elem.scrollHeight > elem.clientHeight) {
alert("code says scroll bar is present on '" +
elemId + "'\n" + elem.scrollHeight +
", " + elem.clientHeight);
} else {
alert("No scroll bar detected for '" +
elemId + "'\n" + elem.scrollHeight +
", " + elem.clientHeight);
}
}
scrollDetect('div1');
scrollDetect('div2');
</script>

Csaba Gabor from Vienna

Aug 11 '05 #3
an**********@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
Aug 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: adrien | last post by:
Hi, (also posted in netscape.public.mozilla.browser) i use netscape 7 and want to hide the scrollbars of the window when something happens. I tried this: window.scrollbars.visible=false...
6
by: CJM | last post by:
I've been trying to tweak the design of a few pages in one of my ASP apps... I'm making sure that the layout is reasonable for resolutions between 800x600 and 1024x768. Since it's almost all...
2
by: Turgeson | last post by:
Is there anyway to determine if a DIV with its overflow style set to auto has the scrollbars visible? I have a dynamically built table inside my DIV. If the table is over a certain height and the...
2
by: delraydog | last post by:
Is there anyway to detect if scrollbars were made visible in a textarea? I'm not talking about initial setting of the scrolling attribute, but rather whether scrollbars have been added either...
1
by: trint | last post by:
I get this error: "WindowsApplication1.Form1.comboBox1' denotes a 'field' where a 'class' was expected" when I do this inside a separate class: "comboBox1.DisplayMember="SourceName"; ...
4
by: Sagaert Johan | last post by:
Hi I used an installer to install my assembly dll into the GAC , with the graphical Gac Tool i see it is installed in the global assembly cache. When in the IDE i add a reference, then the...
1
by: houghm | last post by:
Hello, I'm having a problem and I wonder if anyone can help? I have a div on which I have specified {overflow-y:auto; overflow-x:hidden;}. This div contains a table with a varying number of...
1
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, Is there a way to detect whenever scrollbars (the vertical) are shown on a treeview I need to know. 1) If scrollbars are visible after a rezise 2) If scrollbars are visible after change...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.