Solved

How to findout the ScrollBar Position using JavaScript?

Posted on 2004-10-13
5
2,016 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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.
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
Course of the Month10 days, 18 hours left to enroll

632 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