The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

scrollPosition IE/MZ

I want to calculate how far a page is scrolled down. I found how to do this with Internet Explorer with the following equation: (scrollFrame.document.body.scrollTop / (scrollFrame.document.body.scrollHeight - scrollFrame.document.body.clientHeight)) (where scrollFrame is parent.yourFrameName)
But I canít find it for Mozilla. I have (scrollFrame.window.pageYOffset / (scrollFrame.document.height - scrollFrame.window.innerHeight))
The result of the equation should give 0 when you are at the top of the screen and 1 when you scrolled down. Independent of the window size of course. But that's just what the problem is: As the window size increases, the result of this equation (when you are scrolled all the way down) diverts from 1 to 2.

I tried all suggestions I have had, but none worked. All proposed properties gave the same result as scrollFrame.window.pageYOffset. So I knew it was scrollFrame.document.height - scrollFrame.window.innerHeight that flawed. My solution is than is to search the actual scrollHeight in advance:

Code:

var totalScrollHeight; //the tot scrollHeight of the scrollframe// FOR MZ : Going after the scrollHeight because scrollFrame.window.pageYOffset NOT IS scrollFrame.document.height-scrollFrame.window.innerHeight @ max scrollDownif (document.getElementById){// Scrolling all the way downscrollFrame.scrollTo(0, scrollFrame.document.height);// storing the scrollHeighttotalScrollHeight = scrollFrame.window.pageYOffset;// Scrolling back to the topscrollFrame.scrollTo(0, 0);}

Here I finally have what I thought to find with scrollFrame.document.height - scrollFrame.window.innerHeight

And I just fill it in the equation, resulting in scrollFrame.window.pageYOffset/ totalScrollHeight;

Damn, always searching for the right properties cross-browser scripting is a disaster (even if you assume there are only two browsers)Are there any good cross-browser scripting tutorials or ebooks?

ah, maybe some of the alternative property names are used better than. But anyway it was the fact that scrollFrame.window.pageYOffset NOT IS scrollFrame.document.height-scrollFrame.window.innerHeight @ max scrollDown and the code above solves that problem.