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

Commit 802ed32

Browse files
author
rgalus
committed
1.2.0
1 parent f80f3a6 commit 802ed32

6 files changed

+16
-13
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"test",
1919
"tests"
2020
],
21-
"version": "1.1.9"
21+
"version": "1.2.0"
2222
}

dist/sticky.compile.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
44
* Sticky.js
55
* Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive.
66
*
7-
* @version 1.1.9
7+
* @version 1.2.0
88
* @author Rafal Galus <[email protected]>
99
* @website https://rgalus.github.io/sticky-js/
1010
* @repo https://github.com/rgalus/sticky-js
@@ -27,10 +27,9 @@ var Sticky = function () {
2727
this.selector = selector;
2828
this.elements = [];
2929

30-
this.version = '1.1.9';
30+
this.version = '1.2.0';
3131

3232
this.vp = this.getViewportSize();
33-
this.scrollTop = this.getScrollTopPosition();
3433
this.body = document.querySelector('body');
3534

3635
this.options = {
@@ -41,6 +40,12 @@ var Sticky = function () {
4140
stickyContainer: options.stickyContainer || 'body'
4241
};
4342

43+
this.updateScrollTopPosition = this.updateScrollTopPosition.bind(this);
44+
45+
this.updateScrollTopPosition();
46+
window.addEventListener('load', this.updateScrollTopPosition);
47+
window.addEventListener('scroll', this.updateScrollTopPosition);
48+
4449
this.run();
4550
}
4651

@@ -235,8 +240,6 @@ var Sticky = function () {
235240

236241

237242
Sticky.prototype.onScrollEvents = function onScrollEvents(element) {
238-
this.scrollTop = this.getScrollTopPosition();
239-
240243
if (element.sticky.active) {
241244
this.setPosition(element);
242245
}
@@ -403,14 +406,14 @@ var Sticky = function () {
403406
};
404407

405408
/**
406-
* Function that returns scroll position offset from top
409+
* Function that updates window scroll position
407410
* @function
408411
* @return {number}
409412
*/
410413

411414

412-
Sticky.prototype.getScrollTopPosition = function getScrollTopPosition() {
413-
return (window.pageYOffset || document.scrollTop) - (document.clientTop || 0) || 0;
415+
Sticky.prototype.updateScrollTopPosition = function updateScrollTopPosition() {
416+
this.scrollTop = (window.pageYOffset || document.scrollTop) - (document.clientTop || 0) || 0;
414417
};
415418

416419
/**

dist/sticky.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sticky.min.js.gz

32 Bytes
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sticky-js",
3-
"version": "1.1.9",
3+
"version": "1.2.0",
44
"description": "Sticky elements",
55
"main": "index.js",
66
"scripts": {

src/sticky.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Sticky.js
44
* Library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive.
55
*
6-
* @version 1.1.9
6+
* @version 1.2.0
77
* @author Rafal Galus <[email protected]>
88
* @website https://rgalus.github.io/sticky-js/
99
* @repo https://github.com/rgalus/sticky-js
@@ -21,7 +21,7 @@ class Sticky {
2121
this.selector = selector;
2222
this.elements = [];
2323

24-
this.version = '1.1.9';
24+
this.version = '1.2.0';
2525

2626
this.vp = this.getViewportSize();
2727
this.body = document.querySelector('body');

0 commit comments

Comments
 (0)