Click here to Skip to main content
15,120,078 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to get the scroll bar height which is dragged down ?

I have a page which is having a vertical scroll. I have dragged the scroll bar till the bottom of the page. Now if I use "e.screenY" it will give only the screen height with respect to mouse pointer. If I try to locate a "div" with this "e.screenY"(like this, document.getElementById('divDiscount') = e.screenY - 130 + "px";) it will be located at the top of the page instead of top of the screen. Therefore its not visible to the user. We need to scroll up to see the "div". If I can get scroll height i.e, how much height it has been dragged down, I can locate the div. What would be the solution to this problem?

(Note:If you dint get the question please let me know :) )
koool.kabeer 2-Aug-10 8:41am
do you want the element...
document.getElementById('divDiscount')(may be some other element in asp page)
as Visible Always?....
koool.kabeer 2-Aug-10 8:51am
seems you want that element to be shown even when you are scrolling the Page...
Raghavendra HG 2-Aug-10 9:25am
No I want that div when I click a link inside a grid.

1 solution

You need to put it relative to the document, not the screen I would say.

Here you have some cross browser compatible javascript to get the document height.

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)

...or maybe have a look at this:[^]

Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900