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.10.2
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.10.3
Choose a head ref
  • 11 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 16, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2a752b4 View commit details
  2. Merge pull request #341 from WickyNilliams/bugfix/math-round-scroll-y

    round scroll y values, ensure correct calculation for bottom/top. fixes #315
    WickyNilliams authored Sep 16, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    7391e38 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0b3bf4e View commit details
  4. remove async behaviour of init. fixes #338 (#342)

    remove async behaviour of init. fixes #338
    WickyNilliams authored Sep 16, 2019

    Verified

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

Commits on Sep 18, 2019

  1. Copy the full SHA
    e0530f3 View commit details
  2. Revert "remove async behaviour of init. fixes #338" (#345)

    Revert "remove async behaviour of init. fixes #338"
    WickyNilliams authored Sep 18, 2019
    Copy the full SHA
    50bdaff View commit details
  3. Copy the full SHA
    148e5f9 View commit details
  4. fix top/offset bug

    WickyNilliams committed Sep 18, 2019
    Copy the full SHA
    2ecce36 View commit details
  5. Copy the full SHA
    0996033 View commit details
  6. Bugfix/offset top (#343). fixes #340

    Bugfix/offset top
    WickyNilliams authored Sep 18, 2019
    Copy the full SHA
    fb125a8 View commit details
  7. 0.10.3

    WickyNilliams committed Sep 18, 2019
    Copy the full SHA
    c54c0a3 View commit details
Showing with 25 additions and 25 deletions.
  1. +9 −3 cypress/integration/headroom.spec.js
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +9 −17 src/Headroom.js
  5. +5 −3 src/trackScroll.js
12 changes: 9 additions & 3 deletions cypress/integration/headroom.spec.js
Original file line number Diff line number Diff line change
@@ -88,13 +88,19 @@ describe("Headroom", function() {
});

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

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

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

it("can be frozen / unfrozen", () => {
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.10.2",
"version": "0.10.3",
"description": "Give your page some headroom. Hide your header until you need it",
"main": "dist/headroom.js",
"files": [
26 changes: 9 additions & 17 deletions src/Headroom.js
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ Headroom.prototype = {
function(self) {
self.scrollTracker = trackScroll(
self.scroller,
{ offset: self.offset, tolerance: self.tolerance },
self.update.bind(self)
);
},
@@ -154,18 +155,16 @@ Headroom.prototype = {
}
},

shouldUnpin: function(scrollY, lastScrollY, toleranceExceeded) {
var scrollingDown = scrollY > lastScrollY;
var pastOffset = scrollY >= this.offset;
shouldUnpin: function(details) {
var scrollingDown = details.direction === "down";

return scrollingDown && pastOffset && toleranceExceeded;
return scrollingDown && !details.top && details.toleranceExceeded;
},

shouldPin: function(scrollY, lastScrollY, toleranceExceeded) {
var scrollingUp = scrollY < lastScrollY;
var pastOffset = scrollY <= this.offset;
shouldPin: function(details) {
var scrollingUp = details.direction === "up";

return (scrollingUp && toleranceExceeded) || pastOffset;
return (scrollingUp && details.toleranceExceeded) || details.top;
},

addClass: function(className) {
@@ -181,9 +180,6 @@ Headroom.prototype = {
},

update: function(details) {
var toleranceExceeded =
details.distance > this.tolerance[details.direction];

if (details.isOutOfBounds) {
// Ignore bouncy scrolling in OSX
return;
@@ -205,13 +201,9 @@ Headroom.prototype = {
this.notBottom();
}

if (
this.shouldUnpin(details.scrollY, details.lastScrollY, toleranceExceeded)
) {
if (this.shouldUnpin(details)) {
this.unpin();
} else if (
this.shouldPin(details.scrollY, details.lastScrollY, toleranceExceeded)
) {
} else if (this.shouldPin(details)) {
this.pin();
}
}
8 changes: 5 additions & 3 deletions src/trackScroll.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import { passiveEventsSupported } from "./features";
/**
* @param element EventTarget
*/
export default function trackScroll(element, callback) {
export default function trackScroll(element, options, callback) {
var isPassiveSupported = passiveEventsSupported();
var rafId;
var scrolled = false;
@@ -13,7 +13,7 @@ export default function trackScroll(element, callback) {
var details = {};

function update() {
var scrollY = scroller.scrollY();
var scrollY = Math.round(scroller.scrollY());
var height = scroller.height();
var scrollHeight = scroller.scrollHeight();

@@ -23,8 +23,10 @@ export default function trackScroll(element, callback) {
details.direction = scrollY > lastScrollY ? "down" : "up";
details.distance = Math.abs(scrollY - lastScrollY);
details.isOutOfBounds = scrollY < 0 || scrollY + height > scrollHeight;
details.top = scrollY <= 0;
details.top = scrollY <= options.offset;
details.bottom = scrollY + height >= scrollHeight;
details.toleranceExceeded =
details.distance > options.tolerance[details.direction];

callback(details);