Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
$.fn.offsetRelative
(function () {
"use strict";
var $ = this.jQuery || require('jquery');
function offsetRelative(selector) {
var $el = this;
var $parent = $el.parent();
if (selector) {
$parent = $parent.closest(selector);
}
var elOffset = $el.offset();
var parentOffset = $parent.offset();
return {
left: elOffset.left - parentOffset.left,
top: elOffset.top - parentOffset.top
};
}
// Exports
$.fn.offsetRelative || ($.fn.offsetRelative = offsetRelative);
if (typeof module !== "undefined" && module !== null) {
module.exports = $.fn.offsetRelative;
}
}).call(this);
{
"name": "jquery.offsetRelative",
"version": "0.0.1",
"main": "./jquery.offsetRelative.js",
"author": "Antoine BERNIER"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment