Last active
October 7, 2015 16:08
-
-
Save abernier/3191472 to your computer and use it in GitHub Desktop.
$.fn.offsetRelative
This file contains 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
(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); |
This file contains 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
{ | |
"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