Created
June 3, 2010 09:16
-
-
Save anfedorov/423681 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -- this -- | |
function topOffset(obj) { | |
return obj ? obj.offsetTop + topOffset(obj.offsetParent) : 0; | |
} | |
// --- or this -- | |
function topOffset(obj) { | |
var curtop = 0; | |
if (obj.offsetParent) { | |
do { | |
curtop += obj.offsetTop; | |
} while (obj = obj.offsetParent); | |
return curtop; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment