@linear_non/stellar-libs 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Sticky/index.js +28 -6
package/package.json
CHANGED
package/src/Sticky/index.js
CHANGED
|
@@ -5,13 +5,14 @@ import { kitStore } from "@linear_non/stellar-kit"
|
|
|
5
5
|
|
|
6
6
|
export default class Sticky {
|
|
7
7
|
constructor(obj) {
|
|
8
|
-
const { el, sticky, container, isSmooth, onUpdateCallback } = obj
|
|
8
|
+
const { el, sticky, container, frame, isSmooth, onUpdateCallback } = obj
|
|
9
9
|
|
|
10
10
|
this.el = el
|
|
11
11
|
this.sticky = sticky
|
|
12
12
|
this.isSticky = false
|
|
13
13
|
this.isSmooth = isSmooth
|
|
14
14
|
this.container = container
|
|
15
|
+
this.frame = frame || null
|
|
15
16
|
this.progress = 0
|
|
16
17
|
this.total = 0
|
|
17
18
|
this.positionX = 0
|
|
@@ -97,13 +98,34 @@ export default class Sticky {
|
|
|
97
98
|
resize() {
|
|
98
99
|
if (!this.sticky) return
|
|
99
100
|
|
|
100
|
-
// Get the viewport height dynamically instead of using store
|
|
101
101
|
const vh = window.innerHeight
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
|
|
103
|
+
const stickyRect = bounds(this.el)
|
|
104
|
+
|
|
105
|
+
// HEIGHT (same as you have)
|
|
106
106
|
this.config.totalHeight = this.snap(stickyRect.height - vh)
|
|
107
|
+
|
|
108
|
+
// WIDTH (fix)
|
|
109
|
+
if (!this.container) {
|
|
110
|
+
this.config.totalWidth = 0
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const frameEl = this.frame || this.container.parentElement
|
|
115
|
+
const frameRect = frameEl ? bounds(frameEl) : { width: window.innerWidth }
|
|
116
|
+
|
|
117
|
+
let padL = 0
|
|
118
|
+
let padR = 0
|
|
119
|
+
if (frameEl) {
|
|
120
|
+
const cs = getComputedStyle(frameEl)
|
|
121
|
+
padL = parseFloat(cs.paddingLeft) || 0
|
|
122
|
+
padR = parseFloat(cs.paddingRight) || 0
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const visibleContentWidth = Math.max(0, frameRect.width - padL - padR)
|
|
126
|
+
const totalContentWidth = this.container.scrollWidth || bounds(this.container).width
|
|
127
|
+
|
|
128
|
+
this.config.totalWidth = this.snap(Math.max(0, totalContentWidth - visibleContentWidth))
|
|
107
129
|
}
|
|
108
130
|
|
|
109
131
|
destroy() {
|