tags:

views:

33

answers:

2

I'm hoping to find a way to get the windows position (relative to the total page width/height) so I can use it to force a scroll from one section to another. However, there seems to be a tremendous amount of options when it comes to guessing which object holds the true X/Y for your browser.

Which of these do I need to make sure IE 6+, FF 2+, and Chrome/Safari work?

window.innerWidth
window.innerHeight
window.pageXOffset
window.pageYOffset
document.documentElement.clientWidth
document.documentElement.clientHeight
document.documentElement.scrollLeft
document.documentElement.scrollTop
document.body.clientWidth
document.body.clientHeight
document.body.scrollLeft
document.body.scrollTop

And are there any others? Once I know where the window is I can set an event chain that will slowly call window.scrollBy(x,y); until it reaches that point.

A: 

You should consider using the jQuery ScrollTo plugin.

jtbandes
Thanks, but I don't want to use jQuery.
Xeoncross
+1  A: 

jQuery basically uses:

var doc = document.documentElement, body = document.body;
left = (doc && doc.scrollLeft || body && body.scrollLeft || 0);
right = (doc && doc.scrollTop  || body && body.scrollTop  || 0);

That is, it tests for document.documentElement.scrollLeft first, then tests for and tries document.body.scrollLeft if the other one was zero.

thomasrutter