Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to findout the ScrollBar Position using JavaScript?

Posted on 2004-10-13
5
Medium Priority
?
2,018 Views
Last Modified: 2007-12-19
within the <body> tag, a <div id="content"> ... rest of the body contents goes here ... </div></body>

Upon rendering the page, i have the scroll bars (vertical) enabled.  I can able to scroll it.
but the JS calls, document.body.scrollLeft and document.body.scrollTop are always giving 0 (Zero).

I am testing this with IE.  It works fine in FireFox.
What is the exact problem in this with IE?


Thanks,
Muruga
0
Comment
Question by:mmuruganandam
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 12296572
This works for me:

<html>
<head>
<script>
function moveMenu() {
    for(i = 1 ; i < 5; i++) {
      mDiv = document.getElementById('div_menu_links_'+i);
         if(mDiv)
         {
              mDiv.style.top = (i * 21) + document.body.scrollTop;
              window.status = "top: "+mDiv.style.top;
         }
    }
}
</script>
</head>
<body onScroll="moveMenu()">
<div name="menu_links_1" id="div_menu_links_1" style="top=21; left:0; z-index:106; background-color:yellow; position:absolute;">
<table>
<tr><td>MenuA</td>
<td>MenuB</td>
<td>MenuC</td></tr>
</table>
</div>
<table height="1600" border="1">
<tr><td></td></tr>
</table>
</body>
</html>


0
 
LVL 9

Author Comment

by:mmuruganandam
ID: 12297109
>>document.body.scrollTop
Is there any other way than this.

Because, this is not working for me.  We have some intranet standards.  
All the stylesheets are defined even for DIV.  

Can you give me a different solution?

Thanks
0
 
LVL 5

Expert Comment

by:migoEX
ID: 12297187
Maybe you scrollbar is inside the DIV object, and not the BODY. You can try to retrieve the "scrollTop" property of the DIV element itself.
0
 
LVL 9

Author Comment

by:mmuruganandam
ID: 12297970
I have found out the solution for this.
It can be achieved by document.documentElement.scrollTop.  
It is working fine.

Thanks for your support as always.  
I am confused whether to delete this question or give away points.
Any suggestions guys....
0
 
LVL 17

Accepted Solution

by:
Cem Türk earned 1000 total points
ID: 15628649
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ - Refund

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cem_turk

EE Cleanup Volunteer
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question