Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
[chore] version bump/test => getOffsetTop (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
yowainwright committed May 5, 2018
1 parent e2d9778 commit 7dc63a6
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
9
10
4 changes: 2 additions & 2 deletions dist/jquery.stickybits.min.js

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

27 changes: 23 additions & 4 deletions dist/stickybits.es.js
@@ -1,6 +1,6 @@
/**
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills
@version v3.3.1
@version v3.3.2
@link https://github.com/dollarshaveclub/stickybits#readme
@author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in)
@license MIT
Expand Down Expand Up @@ -50,6 +50,7 @@
- .definePosition = defines sticky or fixed
- .addInstance = an array of objects for each Stickybits Target
- .getClosestParent = gets the parent for non-window scroll
- .getOffsetTop = gets the element offsetTop from the top level of the DOM
- .computeScrollOffsets = computes scroll position
- .toggleClasses = older browser toggler
- .manageState = manages sticky state
Expand All @@ -62,7 +63,7 @@ var Stickybits =
function () {
function Stickybits(target, obj) {
var o = typeof obj !== 'undefined' ? obj : {};
this.version = '3.3.1';
this.version = '3.3.2';
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser';
this.props = {
customStickyChangeNumber: o.customStickyChangeNumber || null,
Expand Down Expand Up @@ -202,6 +203,24 @@ function () {

return p;
};
/*
--------
getOffsetTop
--------
- a helper function that gets the offsetTop of the element
- from the top level of the DOM
*/


_proto.getOffsetTop = function getOffsetTop(el) {
var offsetTop = 0;

do {
offsetTop = el.offsetTop + offsetTop;
} while (el = el.offsetParent);

return offsetTop;
};
/*
computeScrollOffsets 📊
---
Expand All @@ -220,8 +239,8 @@ function () {
var parent = it.parent;
var isCustom = !this.isWin && p.positionVal === 'fixed';
var isBottom = p.verticalPosition !== 'bottom';
var scrollElOffset = isCustom ? p.scrollEl.getBoundingClientRect().top : 0;
var stickyStart = isCustom ? parent.getBoundingClientRect().top - scrollElOffset : parent.getBoundingClientRect().top;
var scrollElOffset = isCustom ? this.getOffsetTop(p.scrollEl) : 0;
var stickyStart = isCustom ? this.getOffsetTop(parent) - scrollElOffset : this.getOffsetTop(parent);
var stickyChangeOffset = p.customStickyChangeNumber !== null ? p.customStickyChangeNumber : el.offsetHeight;
it.offset = scrollElOffset + p.stickyBitStickyOffset;
it.stickyStart = isBottom ? stickyStart - it.offset : 0;
Expand Down
27 changes: 23 additions & 4 deletions dist/stickybits.js
@@ -1,6 +1,6 @@
/**
stickybits - Stickybits is a lightweight alternative to `position: sticky` polyfills
@version v3.3.1
@version v3.3.2
@link https://github.com/dollarshaveclub/stickybits#readme
@author Jeff Wainwright <yowainwright@gmail.com> (https://jeffry.in)
@license MIT
Expand Down Expand Up @@ -56,6 +56,7 @@
- .definePosition = defines sticky or fixed
- .addInstance = an array of objects for each Stickybits Target
- .getClosestParent = gets the parent for non-window scroll
- .getOffsetTop = gets the element offsetTop from the top level of the DOM
- .computeScrollOffsets = computes scroll position
- .toggleClasses = older browser toggler
- .manageState = manages sticky state
Expand All @@ -68,7 +69,7 @@
function () {
function Stickybits(target, obj) {
var o = typeof obj !== 'undefined' ? obj : {};
this.version = '3.3.1';
this.version = '3.3.2';
this.userAgent = window.navigator.userAgent || 'no `userAgent` provided by the browser';
this.props = {
customStickyChangeNumber: o.customStickyChangeNumber || null,
Expand Down Expand Up @@ -208,6 +209,24 @@

return p;
};
/*
--------
getOffsetTop
--------
- a helper function that gets the offsetTop of the element
- from the top level of the DOM
*/


_proto.getOffsetTop = function getOffsetTop(el) {
var offsetTop = 0;

do {
offsetTop = el.offsetTop + offsetTop;
} while (el = el.offsetParent);

return offsetTop;
};
/*
computeScrollOffsets 📊
---
Expand All @@ -226,8 +245,8 @@
var parent = it.parent;
var isCustom = !this.isWin && p.positionVal === 'fixed';
var isBottom = p.verticalPosition !== 'bottom';
var scrollElOffset = isCustom ? p.scrollEl.getBoundingClientRect().top : 0;
var stickyStart = isCustom ? parent.getBoundingClientRect().top - scrollElOffset : parent.getBoundingClientRect().top;
var scrollElOffset = isCustom ? this.getOffsetTop(p.scrollEl) : 0;
var stickyStart = isCustom ? this.getOffsetTop(parent) - scrollElOffset : this.getOffsetTop(parent);
var stickyChangeOffset = p.customStickyChangeNumber !== null ? p.customStickyChangeNumber : el.offsetHeight;
it.offset = scrollElOffset + p.stickyBitStickyOffset;
it.stickyStart = isBottom ? stickyStart - it.offset : 0;
Expand Down

0 comments on commit 7dc63a6

Please sign in to comment.