Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.

Commit f80f3a6

Browse files
author
rgalus
committed
Merge branch 'develop'
2 parents 74113c2 + b73391e commit f80f3a6

File tree

2 files changed

+589
-449
lines changed

2 files changed

+589
-449
lines changed

src/sticky.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class Sticky {
2424
this.version = '1.1.9';
2525

2626
this.vp = this.getViewportSize();
27-
this.scrollTop = this.getScrollTopPosition();
2827
this.body = document.querySelector('body');
2928

3029
this.options = {
@@ -35,6 +34,12 @@ class Sticky {
3534
stickyContainer: options.stickyContainer || 'body',
3635
};
3736

37+
this.updateScrollTopPosition = this.updateScrollTopPosition.bind(this);
38+
39+
this.updateScrollTopPosition();
40+
window.addEventListener('load', this.updateScrollTopPosition);
41+
window.addEventListener('scroll', this.updateScrollTopPosition);
42+
3843
this.run();
3944
}
4045

@@ -215,8 +220,6 @@ class Sticky {
215220
* @param {node} element - Element for which event function is fired
216221
*/
217222
onScrollEvents(element) {
218-
this.scrollTop = this.getScrollTopPosition();
219-
220223
if (element.sticky.active) {
221224
this.setPosition(element);
222225
}
@@ -385,12 +388,12 @@ class Sticky {
385388

386389

387390
/**
388-
* Function that returns scroll position offset from top
391+
* Function that updates window scroll position
389392
* @function
390393
* @return {number}
391394
*/
392-
getScrollTopPosition() {
393-
return (window.pageYOffset || document.scrollTop) - (document.clientTop || 0) || 0;
395+
updateScrollTopPosition() {
396+
this.scrollTop = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0) || 0;
394397
}
395398

396399

0 commit comments

Comments
 (0)