get element position
why this script
This function determines the x and y coordinate of the passed element on the screen.
Although in theory this can be done quite easily by getting using the offsetParent property in a recursive way, in practice you'll encounter some obstacles. Pretty much all examples on the web fail to recognize these obstacles, so here is an attempt at a solution that overcomes them.
The biggest and most apparent problem is the one of elements nested in scrollable divs. In this case the position is returned as if the scrollable element was stretched completely, if you don't compensate. This compensation is done by the second function of this script.
usage
Simply pass any element to the
getElementPosition function and it will return the x & y coordinates in an array.