@@ -14,9 +14,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
14
14
* @repo https://github.com/rgalus/sticky-js
15
15
* @license https://github.com/rgalus/sticky-js/blob/master/LICENSE
16
16
*/
17
- var Sticky =
18
- /*#__PURE__*/
19
- function ( ) {
17
+ var Sticky = /*#__PURE__*/ function ( ) {
20
18
/**
21
19
* Sticky instance constructor
22
20
* @constructor
@@ -36,7 +34,9 @@ function () {
36
34
this . body = document . querySelector ( 'body' ) ;
37
35
this . options = {
38
36
wrap : options . wrap || false ,
37
+ wrapWith : options . wrapWith || '<span></span>' ,
39
38
marginTop : options . marginTop || 0 ,
39
+ marginBottom : options . marginBottom || 0 ,
40
40
stickyFor : options . stickyFor || 0 ,
41
41
stickyClass : options . stickyClass || null ,
42
42
stickyContainer : options . stickyContainer || 'body'
@@ -86,6 +86,7 @@ function () {
86
86
87
87
element . sticky . active = false ;
88
88
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 ;
89
90
element . sticky . stickyFor = parseInt ( element . getAttribute ( 'data-sticky-for' ) ) || this . options . stickyFor ;
90
91
element . sticky . stickyClass = element . getAttribute ( 'data-sticky-class' ) || this . options . stickyClass ;
91
92
element . sticky . wrap = element . hasAttribute ( 'data-sticky-wrap' ) ? true : this . options . wrap ; // @todo attribute for stickyContainer
@@ -118,7 +119,7 @@ function () {
118
119
} , {
119
120
key : "wrapElement" ,
120
121
value : function wrapElement ( element ) {
121
- element . insertAdjacentHTML ( 'beforebegin' , '<span></span>' ) ;
122
+ element . insertAdjacentHTML ( 'beforebegin' , element . getAttribute ( 'data-sticky-wrapWith' ) || this . options . wrapWith ) ;
122
123
element . previousSibling . appendChild ( element ) ;
123
124
}
124
125
/**
@@ -236,7 +237,7 @@ function () {
236
237
} , {
237
238
key : "onScrollEvents" ,
238
239
value : function onScrollEvents ( element ) {
239
- if ( element . sticky . active ) {
240
+ if ( element . sticky && element . sticky . active ) {
240
241
this . setPosition ( element ) ;
241
242
}
242
243
}
@@ -279,20 +280,24 @@ function () {
279
280
left : element . sticky . rect . left + 'px' ,
280
281
width : element . sticky . rect . width + 'px'
281
282
} ) ;
283
+
284
+ if ( element . sticky . stickyClass ) {
285
+ element . classList . add ( element . sticky . stickyClass ) ;
286
+ }
282
287
} else if ( this . scrollTop > element . sticky . rect . top - element . sticky . marginTop ) {
283
288
this . css ( element , {
284
289
position : 'fixed' ,
285
290
width : element . sticky . rect . width + 'px' ,
286
291
left : element . sticky . rect . left + 'px'
287
292
} ) ;
288
293
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 ) {
290
295
if ( element . sticky . stickyClass ) {
291
296
element . classList . remove ( element . sticky . stickyClass ) ;
292
297
}
293
298
294
299
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'
296
301
} ) ;
297
302
} else {
298
303
if ( element . sticky . stickyClass ) {
0 commit comments