javascript get element absolute position

here are some valuable javascript functions for getting window width and height a long with the get element X position, and Y position all of this functions are not my invention; its copied from the website and blog listed in the reference list.

 lets start with getWindowDimension:

function getWindowDime­nsion(isWidth) 

var winW = 630, winH = 460;

if (parseInt(navigator.appVersion)>3) {
­ if (navigator.appName=="Netscape") { winW = window.innerWidth-16; winH = window.innerHeight-16; } if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth-20; winH = document.body.offsetHeight-20;­ }
} return (isWidth)? winW : winH; }

the following are getXPosition and getYPosition:

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; }

­

References

  • http://www.javascripter.net/faq/browserw.htm
  • http://blog.firetree.net/2005/07/04/javascript-find-position/

There are people who are

There are people who are into the field of programming. It is where they can see a lot of opportunities. - Dennis Wong

Powered by Drupal - Design by artinet