/ Published in: JavaScript
Released into the public domain.
Expand |
Embed | Plain Text
function getRealPosition(elmnt) { // h/t to http://www.quirksmode.org/js/findpos.html elmnt = typeof elmnt == 'object' ? elmnt : document.getElementById(elmnt); elmntLeft = elmnt.offsetLeft; elmntTop = elmnt.offsetTop; while(elmnt = elmnt.offsetParent) { elmntLeft += elmnt.offsetLeft; elmntTop += elmnt.offsetTop; } return [elmntLeft, elmntTop]; } function positionBelow(elmntAbove, elmntBelow, topDiff, leftDiff) { elmntAboveRealPosition = getRealPosition(elmntAbove); elmntBelow = typeof elmntBelow == 'object' ? elmntBelow : document.getElementById(elmntBelow); elmntBelow.style.left = elmntAboveRealPosition[0] + (leftDiff ? leftDiff : 0) + 'px'; elmntBelow.style.top = elmntAboveRealPosition[1] + (topDiff ? topDiff : 0) + 'px'; if(elmntBelow.style.position!='absolute') elmntBelow.style.position = 'absolute'; }
You need to login to post a comment.
