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

Commit 3a55eb9

Browse files
committed
update dist
1 parent de2c62e commit 3a55eb9

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

dist/sticky.compile.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
1414
* @repo https://github.com/rgalus/sticky-js
1515
* @license https://github.com/rgalus/sticky-js/blob/master/LICENSE
1616
*/
17-
var Sticky =
18-
/*#__PURE__*/
19-
function () {
17+
var Sticky = /*#__PURE__*/function () {
2018
/**
2119
* Sticky instance constructor
2220
* @constructor
@@ -36,7 +34,9 @@ function () {
3634
this.body = document.querySelector('body');
3735
this.options = {
3836
wrap: options.wrap || false,
37+
wrapWith: options.wrapWith || '<span></span>',
3938
marginTop: options.marginTop || 0,
39+
marginBottom: options.marginBottom || 0,
4040
stickyFor: options.stickyFor || 0,
4141
stickyClass: options.stickyClass || null,
4242
stickyContainer: options.stickyContainer || 'body'
@@ -86,6 +86,7 @@ function () {
8686

8787
element.sticky.active = false;
8888
element.sticky.marginTop = parseInt(element.getAttribute('data-margin-top')) || this.options.marginTop;
89+
element.sticky.marginBottom = parseInt(element.getAttribute('data-margin-bottom')) || this.options.marginBottom;
8990
element.sticky.stickyFor = parseInt(element.getAttribute('data-sticky-for')) || this.options.stickyFor;
9091
element.sticky.stickyClass = element.getAttribute('data-sticky-class') || this.options.stickyClass;
9192
element.sticky.wrap = element.hasAttribute('data-sticky-wrap') ? true : this.options.wrap; // @todo attribute for stickyContainer
@@ -118,7 +119,7 @@ function () {
118119
}, {
119120
key: "wrapElement",
120121
value: function wrapElement(element) {
121-
element.insertAdjacentHTML('beforebegin', '<span></span>');
122+
element.insertAdjacentHTML('beforebegin', element.getAttribute('data-sticky-wrapWith') || this.options.wrapWith);
122123
element.previousSibling.appendChild(element);
123124
}
124125
/**
@@ -236,7 +237,7 @@ function () {
236237
}, {
237238
key: "onScrollEvents",
238239
value: function onScrollEvents(element) {
239-
if (element.sticky.active) {
240+
if (element.sticky && element.sticky.active) {
240241
this.setPosition(element);
241242
}
242243
}
@@ -279,20 +280,24 @@ function () {
279280
left: element.sticky.rect.left + 'px',
280281
width: element.sticky.rect.width + 'px'
281282
});
283+
284+
if (element.sticky.stickyClass) {
285+
element.classList.add(element.sticky.stickyClass);
286+
}
282287
} else if (this.scrollTop > element.sticky.rect.top - element.sticky.marginTop) {
283288
this.css(element, {
284289
position: 'fixed',
285290
width: element.sticky.rect.width + 'px',
286291
left: element.sticky.rect.left + 'px'
287292
});
288293

289-
if (this.scrollTop + element.sticky.rect.height + element.sticky.marginTop > element.sticky.container.rect.top + element.sticky.container.offsetHeight) {
294+
if (this.scrollTop + element.sticky.rect.height + element.sticky.marginTop > element.sticky.container.rect.top + element.sticky.container.offsetHeight - element.sticky.marginBottom) {
290295
if (element.sticky.stickyClass) {
291296
element.classList.remove(element.sticky.stickyClass);
292297
}
293298

294299
this.css(element, {
295-
top: element.sticky.container.rect.top + element.sticky.container.offsetHeight - (this.scrollTop + element.sticky.rect.height) + 'px'
300+
top: element.sticky.container.rect.top + element.sticky.container.offsetHeight - (this.scrollTop + element.sticky.rect.height + element.sticky.marginBottom) + 'px'
296301
});
297302
} else {
298303
if (element.sticky.stickyClass) {

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

65 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)