Solved

How to findout the ScrollBar Position using JavaScript?

Posted on 2004-10-13
5
2,008 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_turk earned 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 86
Test ddwrt:UserLookup 1 22
Asp.net mvc 5 5 19
How can I do a Select All on this page? 8 12
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now