From 9ffcfd98e433b508594feb904554ab6707287fdf Mon Sep 17 00:00:00 2001 From: jcgalindo Date: Sat, 19 Sep 2015 15:20:54 -0430 Subject: [PATCH] Set includeMargin to true to force to include the element's margin in the calculation for outerHeight() and outerWidth() functions. Also, we need to subtract 'margin-left' for x and 'margin-top' for y, on this way we keep the positions for each area. --- src/jquery.nearest.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jquery.nearest.js b/src/jquery.nearest.js index 9cefb0b..8b98e01 100644 --- a/src/jquery.nearest.js +++ b/src/jquery.nearest.js @@ -99,10 +99,10 @@ $all[hasEach2 ? 'each2' : 'each'](function (i, elem) { var $this = hasEach2 ? elem : $(this), off = $this.offset(), - x = off.left, - y = off.top, - w = $this.outerWidth(), - h = $this.outerHeight(), + x = off.left - parseInt($this.css('margin-left')), + y = off.top - parseInt($this.css('margin-top')), + w = $this.outerWidth(true), + h = $this.outerHeight(true), x2 = x + w, y2 = y + h, maxX1 = max(x, point1x), @@ -244,8 +244,8 @@ dimensions = { x: offset.left, y: offset.top, - w: this.outerWidth(), - h: this.outerHeight() + w: this.outerWidth(true), + h: this.outerHeight(true) }; opts = $.extend({}, defaults, dimensions, options || {}); return this.pushStack(nearest(selector, opts, this));