473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test if the scroll bar is at the bottom

How can I test if a vertical scroll bar is at the bottom of the range?
I know that...

document.getEle mentById('mydiv ').scrollHeight

....returns the range, and...

document.getEle mentById('mydiv ').scrollTop

....returns the position of the top of the scroll handle in the range,
but that's not enough information because the scroll handle adds an
arbitrary amount of height. Is there a way to test for the height of
the scroll handle, or is there just a better way to test if the scroll
bar is at the bottom of the range?

Thanks.
Aug 7 '08 #1
3 6448
On Aug 7, 12:12*am, bgold12 <bgol...@gmail. comwrote:
How can I test if a vertical scroll bar is at the bottom of the range?
I know that...

document.getEle mentById('mydiv ').scrollHeight

...returns the range, and...

document.getEle mentById('mydiv ').scrollTop

...returns the position of the top of the scroll handle in the range,
but that's not enough information because the scroll handle adds an
arbitrary amount of height. Is there a way to test for the height of
You need the clientHeight property to complete the equation, but it
has nothing to do with the scrollbar dimensions.
Aug 7 '08 #2
On Aug 7, 12:12*am, bgold12 <bgol...@gmail. comwrote:
How can I test if a vertical scroll bar is at the bottom of the range?
I know that...

document.getEle mentById('mydiv ').scrollHeight

...returns the range, and...

document.getEle mentById('mydiv ').scrollTop

...returns the position of the top of the scroll handle in the range,
but that's not enough information because the scroll handle adds an
arbitrary amount of height. Is there a way to test for the height of
the scroll handle, or is there just a better way to test if the scroll
bar is at the bottom of the range?

Thanks.
var myDiv = document.getEle mentById("myEle ment"); //get the html
element
height = myDiv.scrollHei ght; //total height of
div element
position = myDiv.scrollTop ; //where the
scrollbar is positioned if overflowing...
scrollbar = myDiv.clientHei ght; //the actual
height of scrollbar widget (the blue thingamajiggy)

//to check if the scrollbar is docked at the bottom
//do something like this...
if((height - position) == scrollbar){
alert('scrollba r is docked at the bottom');
}

-bseanvt
Aug 13 '08 #3
On Aug 13, 4:10*pm, bseanvt <bsea...@gmail. comwrote:
On Aug 7, 12:12*am, bgold12 <bgol...@gmail. comwrote:
How can I test if a vertical scroll bar is at the bottom of the range?
I know that...
document.getEle mentById('mydiv ').scrollHeight
...returns the range, and...
document.getEle mentById('mydiv ').scrollTop
...returns the position of the top of the scroll handle in the range,
but that's not enough information because the scroll handle adds an
arbitrary amount of height. Is there a way to test for the height of
the scroll handle, or is there just a better way to test if the scroll
bar is at the bottom of the range?
Thanks.

var myDiv * = document.getEle mentById("myEle ment"); *//get the html
element
height * * *= myDiv.scrollHei ght; * * * * * * * ** *//total height of
div element
position * *= myDiv.scrollTop ; * * * * * * * * * * * //where the
scrollbar is positioned if overflowing...
scrollbar * = myDiv.clientHei ght; * * * * * * * * **//the actual
height of scrollbar widget (the blue thingamajiggy)

//to check if the scrollbar is docked at the bottom
//do something like this...
if((height - position) == scrollbar){
* alert('scrollba r is docked at the bottom');

}

-bseanvt
oops... made a mistake... need to add those vars together. here is the
code:

var container = document.getEle mentById("my_co ntainer");
height = container.clien tHeight;
scroll = container.scrol lHeight;
positon = container.scrol lTop;

if((height + position) == scroll){
/* do something here like reposition scrollbar */
container.scrol lTop = 123;
}
Aug 14 '08 #4

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

Similar topics

3
10202
by: AES/newspost | last post by:
Just been involved with a web site where clicking a button on the main page opened a second (or secondary) window intended to function like a dialog box in Apple GUI jargon. (The primary page was a private nonprofit organization's home page and the secondary window was actually an election ballot.) The secondary window opened smaller than the primary page, both vertically and horizontally, with a vertical scroll bar which had the usual...
4
7208
by: Mad Scientist Jr | last post by:
I have a textbox that i am adding to (in codebehind of ASP.NET) and need to ensure that the focus is scrolled to the bottom of the textbox each time the page refreshes, and then set focus to a 2nd textbox (which the user types input into). I have tried a couple functions I found posted online but they don't work (see below) The closest I got was using the scrolldown method:
14
12511
by: Simon Wigzell | last post by:
I want to display HTML text inside a div and have the page open scrolled to the bottom. (My div has overflow:auto so that it appears with scroll bars) I have found this that works on a textarea: document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight; But this doesn't work on a div. I am using a div because the text I am displaying contains HTML. Surely it is possible to simply set a scroll bar to the bottom in a div???...
1
15580
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could tell me to scroll the richtextbox's content to bottom if there it has enough text to make a scroll that is. everytime i append text to it i would like it to scroll to bottom, how is that done? /Lasse
7
69311
by: Mel Weaver | last post by:
Hello, How do you scroll to the bottom of a multiline textbox in code? Mel
4
2329
by: John Dann | last post by:
I have a listview control on a simple vb.net form that's populated programmatically. It is set to scrollable and a scroll bar duly appears. However the scroll bar doesn't allow the bottom rows of the list to be seen. For example, if I have 31 rows in the list with the control set to a height that shows maybe 20 rows then the scroll bar allows me to get down to eg row 28 as the bottom row, but not row 31. Yet if I drag the bottom of the...
0
1687
by: jasondavidcarr | last post by:
Hello all, I have a "comments" page that contains three sections; the article to be commented on is on top, followed by previous comments, and on the bottom a place to add new comments. It's a pretty common scenario. I have two links from the main article page; one to view the comments and one to add a new comment. I'm simply using <span id="top"and <span id="bottom">, and #top or #bottom in the query string to distinguish between...
6
10660
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value = m_vScrollBar.Maximum; The scroll bar is set to start from the bottom.
2
2638
by: Paul Neave | last post by:
Hello all. Please try this link for me and let me know what you see: http://www.neave.com/temp/stretch_test.html You should see a green header filling the top of the page, a red footer at the very bottom of the page and a white Flash movie filling the gap in between. You'll need at least Flash Player 7, otherwise it will just show black. It shouldn't scroll, it should act like a framed page but
0
7877
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
8253
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
8374
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...
0
8240
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
6661
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
3867
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.