Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'up' and 'down' values for offset option #297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Headroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
},
Expand All @@ -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;
},
Expand All @@ -345,7 +345,7 @@ Headroom.prototype = {
return;
}

if (currentScrollY <= this.offset ) {
if (currentScrollY <= this.offset['up'] ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndClarke shouldn't this be this.offset['down']?

this.top();
} else {
this.notTop();
Expand Down Expand Up @@ -377,7 +377,10 @@ Headroom.options = {
up : 0,
down : 0
},
offset : 0,
offset : {
up : 0,
down : 0
},
scroller: window,
classes : {
pinned : 'headroom--pinned',
Expand Down