Scroll the page to the current object

This code will allow you to scroll the page in javascript to the current selected object
JavaScript


function jumpScroll(obj) {
   	window.scroll(0,findPosY(obj)); // horizontal and vertical scroll targets
};

function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        } else if(obj.x)
        curleft += obj.x;
    return curleft;
};

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1) {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        } else if(obj.y)
        curtop += obj.y;
    return curtop;
}

Written by Frank Joseph Brefere III

Posted by fbrefere001 on Thursday August 16, 2007