From c013eac2127b91c03010e84878ecff70abfe5c92 Mon Sep 17 00:00:00 2001 From: Andrew Clarke Date: Tue, 20 Feb 2018 19:52:50 -0500 Subject: [PATCH 1/2] Added 'up' and 'down' values for offset option --- src/Headroom.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Headroom.js b/src/Headroom.js index 5d6387e..7cfb38f 100644 --- a/src/Headroom.js +++ b/src/Headroom.js @@ -39,7 +39,7 @@ function extend (object /*, objectN ... */) { /** * Helper function for normalizing tolerance option to object format */ -function normalizeTolerance (t) { +function normalizeUpDownObject (t) { return t === Object(t) ? t : { down : t, up : t }; } @@ -56,9 +56,9 @@ function Headroom (elem, options) { this.lastKnownScrollY = 0; this.elem = elem; - this.tolerance = normalizeTolerance(options.tolerance); + this.tolerance = normalizeUpDownObject(options.tolerance); this.classes = options.classes; - this.offset = options.offset; + this.offset = normalizeUpDownObject(options.offset); this.scroller = options.scroller; this.initialised = false; this.onPin = options.onPin; @@ -315,7 +315,7 @@ Headroom.prototype = { */ shouldUnpin : function (currentScrollY, toleranceExceeded) { var scrollingDown = currentScrollY > this.lastKnownScrollY, - pastOffset = currentScrollY >= this.offset; + pastOffset = currentScrollY >= this.offset['down']; return scrollingDown && pastOffset && toleranceExceeded; }, @@ -328,7 +328,7 @@ Headroom.prototype = { */ shouldPin : function (currentScrollY, toleranceExceeded) { var scrollingUp = currentScrollY < this.lastKnownScrollY, - pastOffset = currentScrollY <= this.offset; + pastOffset = currentScrollY <= this.offset['up']; return (scrollingUp && toleranceExceeded) || pastOffset; }, @@ -377,7 +377,10 @@ Headroom.options = { up : 0, down : 0 }, - offset : 0, + offset : { + up : 0, + down : 0 + }, scroller: window, classes : { pinned : 'headroom--pinned', From 041ca7dbc113c47886e16cc3e1e9d7a19eac9e45 Mon Sep 17 00:00:00 2001 From: Andrew Clarke Date: Tue, 20 Feb 2018 20:36:06 -0500 Subject: [PATCH 2/2] amendment to previous commit --- src/Headroom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Headroom.js b/src/Headroom.js index 7cfb38f..6f30fbe 100644 --- a/src/Headroom.js +++ b/src/Headroom.js @@ -345,7 +345,7 @@ Headroom.prototype = { return; } - if (currentScrollY <= this.offset ) { + if (currentScrollY <= this.offset['up'] ) { this.top(); } else { this.notTop();