Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created March 18, 2009 05:43
Show Gist options
  • Save hisasann/80964 to your computer and use it in GitHub Desktop.
Save hisasann/80964 to your computer and use it in GitHub Desktop.
(function($){
$.fn.getRelativeOffset = function(name){
var elem = this[0],
top = 0,
left = 0;
// require relative
if($(name).css("position") != "relative")
$(name).css("position", "relative")
while(elem){
left += elem.offsetLeft;
top += elem.offsetTop;
if(elem.offsetParent === $(name)[0])
break;
elem = elem.offsetParent;
}
return {
left : left, top : top
};
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment