Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: WickyNilliams/headroom.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.11.0
Choose a base ref
...
head repository: WickyNilliams/headroom.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.12.0
Choose a head ref
  • 3 commits
  • 5 files changed
  • 3 contributors

Commits on Aug 20, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    feb8492 View commit details

Commits on Oct 16, 2020

  1. Merge pull request #370 from matthewnessworthy/separate-up-down-offse…

    …t-values
    
    add support for separate up/down offset values
    WickyNilliams authored Oct 16, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    1c93dad View commit details
  2. 0.12.0

    WickyNilliams committed Oct 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0f53fc7 View commit details
Showing with 35 additions and 5 deletions.
  1. +29 −0 cypress/integration/headroom.spec.js
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +3 −2 src/Headroom.js
  5. +1 −1 src/trackScroll.js
29 changes: 29 additions & 0 deletions cypress/integration/headroom.spec.js
Original file line number Diff line number Diff line change
@@ -106,6 +106,35 @@ describe("Headroom", function() {
.should("be.top");
});

it("handles up/down offset correctly", () => {
initialiseHeadroom({
offset: {
up: 70,
down: 120,
}
});

cy.scrollTo(0, 119);
cy.get("header")
.should("be.initialised")
.should("be.top");

cy.scrollTo(0, 140);
cy.get("header")
.should("not.be.pinned")
.should("not.be.top");

cy.scrollTo(0, 121);
cy.get("header")
.should("be.pinned")
.should("not.be.top");

cy.scrollTo(0, 69);
cy.get("header")
.should("be.pinned")
.should("be.top");
});

it("can be frozen / unfrozen", () => {
initialiseHeadroom();

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "headroom.js",
"version": "0.11.0",
"version": "0.12.0",
"description": "Give your page some headroom. Hide your header until you need it",
"main": "dist/headroom.js",
"files": [
5 changes: 3 additions & 2 deletions src/Headroom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isBrowser, isSupported } from "./features";
import trackScroll from "./trackScroll";

function normalizeTolerance(t) {
function normalizeUpDown(t) {
return t === Object(t) ? t : { down: t, up: t };
}

@@ -19,7 +19,8 @@ function Headroom(elem, options) {
this.classes = Object.assign({}, Headroom.options.classes, options.classes);

this.elem = elem;
this.tolerance = normalizeTolerance(this.tolerance);
this.tolerance = normalizeUpDown(this.tolerance);
this.offset = normalizeUpDown(this.offset);
this.initialised = false;
this.frozen = false;
}
2 changes: 1 addition & 1 deletion src/trackScroll.js
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ export default function trackScroll(element, options, callback) {
details.direction = scrollY > lastScrollY ? "down" : "up";
details.distance = Math.abs(scrollY - lastScrollY);
details.isOutOfBounds = scrollY < 0 || scrollY + height > scrollHeight;
details.top = scrollY <= options.offset;
details.top = scrollY <= options.offset[details.direction];
details.bottom = scrollY + height >= scrollHeight;
details.toleranceExceeded =
details.distance > options.tolerance[details.direction];