Skip to content

Commit 798469a

Browse files
committed
Added offsetTop feature
1 parent a7254cf commit 798469a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/web/mage/sticky.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ define([
1313
options: {
1414
container: '',
1515
spacingTop: 0,
16+
offsetTop: 0,
1617
stickyClass: '_sticky'
1718
},
1819

@@ -52,6 +53,22 @@ define([
5253

5354
offset = Math.max( 0, Math.min( offset, this.maxOffset) );
5455

56+
if (offset &&
57+
this.options.offsetTop &&
58+
!this.element.hasClass(this.options.stickyClass)) {
59+
60+
var offsetTop = 0;
61+
if (typeof this.options.offsetTop === 'function') {
62+
offsetTop = this.options.offsetTop();
63+
} else {
64+
offsetTop = this.options.offsetTop;
65+
}
66+
67+
if (offset < this.options.offsetTop) {
68+
offset = 0;
69+
}
70+
}
71+
5572
this.element
5673
.toggleClass(this.options.stickyClass, (offset > 0))
5774
.css( 'top', offset );

0 commit comments

Comments
 (0)