Solved

How to findout the ScrollBar Position using JavaScript?

Posted on 2004-10-13
5
2,013 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

752 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