- function DL_GetElementLeft(eElement)
- {
- if (!eElement && this) // if argument is invalid
- { // (not specified, is null or is 0)
- eElement = this; // and function is a method
- } // identify the element as the method owner
- var nLeftPos = eElement.offsetLeft; // initialize var to store calculations
- var eParElement = eElement.offsetParent; // identify first offset parent element
- while (eParElement != null)
- { // move up through element hierarchy
- nLeftPos += eParElement.offsetLeft; // appending left offset of each parent
- eParElement = eParElement.offsetParent; // until no more offset parents exist
- }
- return nLeftPos; // return the number calculated
- }
- function DL_GetElementTop(eElement)
- {
- if (!eElement && this)
- {
- eElement = this;
- }
- var nTopPos = eElement.offsetTop;
- var eParElement = eElement.offsetParent;
- while (eParElement != null)
- {
- nTopPos += eParElement.offsetTop;
- eParElement = eParElement.offsetParent;
- }
- return nTopPos;
- }
- //该片段来自于http://www.codesnippet.cn/detail/201220121091.html
来源: http://www.codesnippet.cn/detail/201220121091.html