Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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