Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created June 3, 2010 09:16
Show Gist options
  • Save anfedorov/423681 to your computer and use it in GitHub Desktop.
Save anfedorov/423681 to your computer and use it in GitHub Desktop.
// -- 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