Monday, November 23, 2009

JavaScript - Find position

This is kind of a useful script for setting the window's scroll position to that of an object's in javascript.

function Scroll2Pos(cID) 
{
var obj = document.getElementById(cID);
var curtop = 0;
if (obj.offsetParent)
{
do
{
curtop += obj.offsetTop;
}
while (obj = obj.offsetParent);
window.scrollTo(0, curtop);
}
}

It is based on this.

JavaScript - Find position


No comments: