473,725 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17311
I think I have sorted the problem

if (document.getEl ementById('divI D').scrollHeigh t >
document.getEle mentById('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**********@to talise.co.uk wrote:
I think I have sorted the problem

if (document.getEl ementById('divI D').scrollHeigh t >
document.getEle mentById('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:1 px solid
red;width:120px ;height:50px;ov erflow:auto">
There_once_was_ a_boy_from_nod_ Who_carried_a_l ot_of_sod</div><br>

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

<script type='text/javascript'>
function scrollDetect(el emId) {
var elem = document.getEle mentById(elemId );
if (elem.scrollHei ght > elem.clientHeig ht) {
alert("code says scroll bar is present on '" +
elemId + "'\n" + elem.scrollHeig ht +
", " + elem.clientHeig ht);
} else {
alert("No scroll bar detected for '" +
elemId + "'\n" + elem.scrollHeig ht +
", " + elem.clientHeig ht);
}
}
scrollDetect('d iv1');
scrollDetect('d iv2');
</script>

Csaba Gabor from Vienna

Aug 11 '05 #3
an**********@to talise.co.uk wrote :
I think I have sorted the problem

if (document.getEl ementById('divI D').scrollHeigh t >
document.getEle mentById('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
11488
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 window.scrollbars.visibility="no" .... nothing works Is it also possible only to hide the vertical scrollbar instead of both?
6
3378
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 forms (rather than text) it takes a bit of extra effort to find the right balance. At the higher resolution, everything is fine. When I reduce the IE window to 800x600 (via bookmarklet), I'm getting both horizontal and vertical scrollbars; the...
2
4328
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 scrollbars appear, I want to shrink the width of my table. If the table's height doesn't exceed the div's height, I want the table to be the same width as the div. Any ideas? *** Sent via Developersdex http://www.developersdex.com ***
2
10736
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 horizontally or vertically based on the users text input? Thanks, Cliff.
1
1401
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"; PaperSource pkSource; for (int i = 0; i < pd.PrinterSettings.PaperSources.Count; i++) { pkSource = pd.PrinterSettings.PaperSources;
4
4136
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 assembly is not visible in listview. How to make my assembly visible in this list ? johan
1
2083
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 rows. When the rows excede the number which will fit in the div (which also has a height) then the vertical scrollbars appear. In firefox this works correctly, but in IE7 the scrollbars appear inside the content space - that is, the table content...
1
6240
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 in content (e.g. nodes collapsed/expanded, nodes added/deleted ). Any event to hook into?
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.