@linear_non/stellar-libs 1.0.2 → 1.0.3
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/ScrollBar/index.js +61 -61
- package/src/Smooth/index.js +79 -80
- package/src/SplitOnScroll/index.js +23 -23
- package/src/Sticky/index.js +48 -55
- package/src/index.js +4 -4
package/package.json
CHANGED
package/src/ScrollBar/index.js
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
1
|
// Scrollbar.js
|
|
2
|
-
import { kitStore } from "@linear_non/stellar-kit"
|
|
3
|
-
import { emitter, EVENTS, Raf } from "@linear_non/stellar-kit/events"
|
|
2
|
+
import { kitStore } from "@linear_non/stellar-kit"
|
|
3
|
+
import { emitter, EVENTS, Raf } from "@linear_non/stellar-kit/events"
|
|
4
4
|
|
|
5
5
|
export default class Scrollbar {
|
|
6
6
|
constructor(obj) {
|
|
7
|
-
this.container = obj.container || document.body
|
|
8
|
-
this.el = null
|
|
9
|
-
this.handle = null
|
|
10
|
-
this.touching = false
|
|
7
|
+
this.container = obj.container || document.body
|
|
8
|
+
this.el = null
|
|
9
|
+
this.handle = null
|
|
10
|
+
this.touching = false
|
|
11
11
|
|
|
12
12
|
this.state = {
|
|
13
13
|
clicked: false,
|
|
14
14
|
scale: 0,
|
|
15
15
|
current: 0,
|
|
16
|
-
}
|
|
17
|
-
this.height = 0
|
|
18
|
-
this.init()
|
|
16
|
+
}
|
|
17
|
+
this.height = 0
|
|
18
|
+
this.init()
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
init() {
|
|
22
|
-
this.create()
|
|
23
|
-
this.setBounds()
|
|
24
|
-
this.on()
|
|
22
|
+
this.create()
|
|
23
|
+
this.setBounds()
|
|
24
|
+
this.on()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
on() {
|
|
28
|
-
emitter.on(EVENTS.APP_TICK, this.tick)
|
|
29
|
-
emitter.on(EVENTS.APP_RESIZE, this.resize)
|
|
30
|
-
this.handle.addEventListener("mousedown", this.mouseDown)
|
|
31
|
-
window.addEventListener("mouseup", this.mouseUp)
|
|
32
|
-
window.addEventListener("mousemove", this.mouseMove)
|
|
28
|
+
emitter.on(EVENTS.APP_TICK, this.tick)
|
|
29
|
+
emitter.on(EVENTS.APP_RESIZE, this.resize)
|
|
30
|
+
this.handle.addEventListener("mousedown", this.mouseDown)
|
|
31
|
+
window.addEventListener("mouseup", this.mouseUp)
|
|
32
|
+
window.addEventListener("mousemove", this.mouseMove)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
off() {
|
|
36
|
-
emitter.off(EVENTS.APP_TICK, this.tick)
|
|
37
|
-
emitter.off(EVENTS.APP_RESIZE, this.resize)
|
|
38
|
-
this.handle.removeEventListener("mousedown", this.mouseDown)
|
|
39
|
-
window.removeEventListener("mouseup", this.mouseUp)
|
|
40
|
-
window.removeEventListener("mousemove", this.mouseMove)
|
|
36
|
+
emitter.off(EVENTS.APP_TICK, this.tick)
|
|
37
|
+
emitter.off(EVENTS.APP_RESIZE, this.resize)
|
|
38
|
+
this.handle.removeEventListener("mousedown", this.mouseDown)
|
|
39
|
+
window.removeEventListener("mouseup", this.mouseUp)
|
|
40
|
+
window.removeEventListener("mousemove", this.mouseMove)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
mouseDown = () => {
|
|
44
|
-
this.touching = true
|
|
45
|
-
document.body.style.userSelect = "none"
|
|
46
|
-
document.body.style.webkitUserSelect = "none"
|
|
47
|
-
document.body.style.pointerEvents = "none"
|
|
48
|
-
}
|
|
44
|
+
this.touching = true
|
|
45
|
+
document.body.style.userSelect = "none"
|
|
46
|
+
document.body.style.webkitUserSelect = "none"
|
|
47
|
+
document.body.style.pointerEvents = "none"
|
|
48
|
+
}
|
|
49
49
|
|
|
50
50
|
mouseUp = () => {
|
|
51
|
-
this.touching = false
|
|
52
|
-
document.body.style.userSelect = "inherit"
|
|
53
|
-
document.body.style.webkitUserSelect = "inherit"
|
|
54
|
-
document.body.style.pointerEvents = "inherit"
|
|
55
|
-
}
|
|
51
|
+
this.touching = false
|
|
52
|
+
document.body.style.userSelect = "inherit"
|
|
53
|
+
document.body.style.webkitUserSelect = "inherit"
|
|
54
|
+
document.body.style.pointerEvents = "inherit"
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
mouseMove =
|
|
57
|
+
mouseMove = e => {
|
|
58
58
|
if (this.touching === true) {
|
|
59
|
-
const { isLocked } = kitStore.flags
|
|
59
|
+
const { isLocked } = kitStore.flags
|
|
60
60
|
|
|
61
|
-
if (isLocked) return
|
|
61
|
+
if (isLocked) return
|
|
62
62
|
|
|
63
|
-
kitStore.raf.scroll.target = e.clientY * this.state.scale
|
|
64
|
-
kitStore.raf.clamp()
|
|
63
|
+
kitStore.raf.scroll.target = e.clientY * this.state.scale
|
|
64
|
+
kitStore.raf.clamp()
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
}
|
|
67
67
|
|
|
68
68
|
setBounds() {
|
|
69
|
-
const { vh, fh } = kitStore.sizes
|
|
70
|
-
const scrollLimit = fh
|
|
71
|
-
this.state.scale = (scrollLimit + vh) / vh
|
|
72
|
-
this.handle.style.height = `${vh / this.state.scale}px
|
|
69
|
+
const { vh, fh } = kitStore.sizes
|
|
70
|
+
const scrollLimit = fh
|
|
71
|
+
this.state.scale = (scrollLimit + vh) / vh
|
|
72
|
+
this.handle.style.height = `${vh / this.state.scale}px`
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
tick = ({ current }) => {
|
|
76
|
-
const scroll = current / this.state.scale
|
|
77
|
-
this.state.current = scroll
|
|
78
|
-
this.handle.style.transform = `translate3d(0, ${this.state.current}px, 0)
|
|
79
|
-
}
|
|
76
|
+
const scroll = current / this.state.scale
|
|
77
|
+
this.state.current = scroll
|
|
78
|
+
this.handle.style.transform = `translate3d(0, ${this.state.current}px, 0)`
|
|
79
|
+
}
|
|
80
80
|
|
|
81
81
|
resize = () => {
|
|
82
|
-
this.setBounds()
|
|
83
|
-
}
|
|
82
|
+
this.setBounds()
|
|
83
|
+
}
|
|
84
84
|
|
|
85
85
|
calcScroll(e) {
|
|
86
|
-
const delta = e.clientY * this.state.scale
|
|
87
|
-
Raf.target = delta
|
|
88
|
-
Raf.clampTarget()
|
|
86
|
+
const delta = e.clientY * this.state.scale
|
|
87
|
+
Raf.target = delta
|
|
88
|
+
Raf.clampTarget()
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
create() {
|
|
92
|
-
this.el = document.createElement("div")
|
|
93
|
-
this.handle = document.createElement("div")
|
|
94
|
-
this.el.classList.add("scrollbar")
|
|
95
|
-
this.handle.classList.add("handle")
|
|
92
|
+
this.el = document.createElement("div")
|
|
93
|
+
this.handle = document.createElement("div")
|
|
94
|
+
this.el.classList.add("scrollbar")
|
|
95
|
+
this.handle.classList.add("handle")
|
|
96
96
|
|
|
97
97
|
Object.assign(this.el.style, {
|
|
98
98
|
position: "fixed",
|
|
@@ -100,7 +100,7 @@ export default class Scrollbar {
|
|
|
100
100
|
right: 0,
|
|
101
101
|
height: "100%",
|
|
102
102
|
pointerEvents: "all",
|
|
103
|
-
})
|
|
103
|
+
})
|
|
104
104
|
|
|
105
105
|
Object.assign(this.handle.style, {
|
|
106
106
|
position: "absolute",
|
|
@@ -109,17 +109,17 @@ export default class Scrollbar {
|
|
|
109
109
|
width: "100%",
|
|
110
110
|
cursor: "pointer",
|
|
111
111
|
zIndex: 101,
|
|
112
|
-
})
|
|
112
|
+
})
|
|
113
113
|
|
|
114
|
-
this.container.appendChild(this.el)
|
|
115
|
-
this.el.appendChild(this.handle)
|
|
114
|
+
this.container.appendChild(this.el)
|
|
115
|
+
this.el.appendChild(this.handle)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
update() {
|
|
119
|
-
this.setBounds()
|
|
119
|
+
this.setBounds()
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
destroy() {
|
|
123
|
-
this.off()
|
|
123
|
+
this.off()
|
|
124
124
|
}
|
|
125
125
|
}
|
package/src/Smooth/index.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
// Smooth.js
|
|
2
|
-
import Scrollbar from "../ScrollBar"
|
|
3
|
-
import { kitStore } from "@linear_non/stellar-kit"
|
|
4
|
-
import { emitter, EVENTS } from "@linear_non/stellar-kit/events"
|
|
5
|
-
import { qs, qsa, bounds } from "@linear_non/stellar-kit/utils"
|
|
2
|
+
import Scrollbar from "../ScrollBar"
|
|
3
|
+
import { kitStore } from "@linear_non/stellar-kit"
|
|
4
|
+
import { emitter, EVENTS } from "@linear_non/stellar-kit/events"
|
|
5
|
+
import { qs, qsa, bounds } from "@linear_non/stellar-kit/utils"
|
|
6
6
|
|
|
7
7
|
export default class Smooth {
|
|
8
8
|
constructor(obj) {
|
|
9
|
-
this.scroll = obj.scroll
|
|
10
|
-
this.el = qs("[data-view]")
|
|
11
|
-
this.elems = null
|
|
12
|
-
this.current = 0
|
|
13
|
-
this.threshold = 100
|
|
14
|
-
this.sections = null
|
|
15
|
-
this.scrollbar = null
|
|
16
|
-
this.init()
|
|
9
|
+
this.scroll = obj.scroll
|
|
10
|
+
this.el = qs("[data-view]")
|
|
11
|
+
this.elems = null
|
|
12
|
+
this.current = 0
|
|
13
|
+
this.threshold = 100
|
|
14
|
+
this.sections = null
|
|
15
|
+
this.scrollbar = null
|
|
16
|
+
this.init()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
getSections() {
|
|
20
|
-
const { isSmooth } = kitStore.flags
|
|
21
|
-
if (!this.elems || !isSmooth) return
|
|
20
|
+
const { isSmooth } = kitStore.flags
|
|
21
|
+
if (!this.elems || !isSmooth) return
|
|
22
22
|
|
|
23
|
-
this.sections = []
|
|
24
|
-
this.elems.forEach(
|
|
25
|
-
el.style.transform = "translate3d(0, 0, 0)"
|
|
26
|
-
const speed = el.dataset.speed || 1
|
|
27
|
-
const { top, bottom, offset } = this.getVars(el, speed)
|
|
28
|
-
let parent = el.parentNode.closest("[data-smooth]")
|
|
23
|
+
this.sections = []
|
|
24
|
+
this.elems.forEach(el => {
|
|
25
|
+
el.style.transform = "translate3d(0, 0, 0)"
|
|
26
|
+
const speed = el.dataset.speed || 1
|
|
27
|
+
const { top, bottom, offset } = this.getVars(el, speed)
|
|
28
|
+
let parent = el.parentNode.closest("[data-smooth]")
|
|
29
29
|
|
|
30
30
|
if (parent) {
|
|
31
|
-
this.sections.some(
|
|
32
|
-
if (obj.el === parent) parent = obj
|
|
33
|
-
})
|
|
31
|
+
this.sections.some(obj => {
|
|
32
|
+
if (obj.el === parent) parent = obj
|
|
33
|
+
})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
this.sections.push({
|
|
@@ -42,108 +42,107 @@ export default class Smooth {
|
|
|
42
42
|
speed,
|
|
43
43
|
out: true,
|
|
44
44
|
transform: 0,
|
|
45
|
-
})
|
|
46
|
-
})
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
tick = ({ current }) => {
|
|
50
|
-
this.current = current
|
|
51
|
-
this.transformSections()
|
|
52
|
-
}
|
|
50
|
+
this.current = current
|
|
51
|
+
this.transformSections()
|
|
52
|
+
}
|
|
53
53
|
|
|
54
54
|
transformSections() {
|
|
55
|
-
const { isSmooth, isResizing } = kitStore.flags
|
|
56
|
-
if (!this.sections || !isSmooth) return
|
|
55
|
+
const { isSmooth, isResizing } = kitStore.flags
|
|
56
|
+
if (!this.sections || !isSmooth) return
|
|
57
57
|
|
|
58
|
-
this.sections.forEach(
|
|
59
|
-
const { isVisible, transform } = this.isVisible(section)
|
|
58
|
+
this.sections.forEach(section => {
|
|
59
|
+
const { isVisible, transform } = this.isVisible(section)
|
|
60
60
|
|
|
61
61
|
if (isVisible || isResizing || !section.out) {
|
|
62
|
-
section.out = !isVisible
|
|
63
|
-
section.transform = transform
|
|
64
|
-
section.el.style.transform = this.getTransform(transform)
|
|
62
|
+
section.out = !isVisible
|
|
63
|
+
section.transform = transform
|
|
64
|
+
section.el.style.transform = this.getTransform(transform)
|
|
65
65
|
}
|
|
66
|
-
})
|
|
66
|
+
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
isVisible(section) {
|
|
70
|
-
const { vh } = kitStore.sizes
|
|
71
|
-
const { top, bottom, offset, speed, parent } = section
|
|
70
|
+
const { vh } = kitStore.sizes
|
|
71
|
+
const { top, bottom, offset, speed, parent } = section
|
|
72
72
|
|
|
73
|
-
const extra = (parent && parent.transform) || 0
|
|
74
|
-
const translate = this.current * speed
|
|
75
|
-
const transform = translate - offset - extra
|
|
76
|
-
const start = top - translate
|
|
77
|
-
const end = bottom - translate
|
|
78
|
-
const isVisible = start < this.threshold + vh && end > -this.threshold
|
|
73
|
+
const extra = (parent && parent.transform) || 0
|
|
74
|
+
const translate = this.current * speed
|
|
75
|
+
const transform = translate - offset - extra
|
|
76
|
+
const start = top - translate
|
|
77
|
+
const end = bottom - translate
|
|
78
|
+
const isVisible = start < this.threshold + vh && end > -this.threshold
|
|
79
79
|
|
|
80
|
-
return { isVisible, transform }
|
|
80
|
+
return { isVisible, transform }
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
getTransform(transform) {
|
|
84
|
-
return `translate3d(0, ${-transform}px, 0)
|
|
84
|
+
return `translate3d(0, ${-transform}px, 0)`
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
getVars(el, speed) {
|
|
88
|
-
const { vh } = kitStore.sizes
|
|
89
|
-
const rect = bounds(el)
|
|
90
|
-
const centering = vh / 2 - rect.height / 2
|
|
91
|
-
const offset =
|
|
92
|
-
rect.top < vh
|
|
93
|
-
? 0
|
|
94
|
-
: (rect.top - centering) * speed - (rect.top - centering);
|
|
88
|
+
const { vh } = kitStore.sizes
|
|
89
|
+
const rect = bounds(el)
|
|
90
|
+
const centering = vh / 2 - rect.height / 2
|
|
91
|
+
const offset = rect.top < vh ? 0 : (rect.top - centering) * speed - (rect.top - centering)
|
|
95
92
|
|
|
96
93
|
return {
|
|
97
94
|
top: rect.top + offset,
|
|
98
95
|
bottom: rect.bottom + offset,
|
|
99
96
|
offset,
|
|
100
|
-
}
|
|
97
|
+
}
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
resize = () => {
|
|
104
|
-
if (!this.sections) return
|
|
101
|
+
if (!this.sections) return
|
|
105
102
|
|
|
106
|
-
this.sections.forEach(
|
|
107
|
-
section.el.style.transform = "translate3d(0, 0, 0)"
|
|
108
|
-
const { top, bottom, offset } = this.getVars(section.el, section.speed)
|
|
109
|
-
Object.assign(section, { top, bottom, offset })
|
|
110
|
-
})
|
|
103
|
+
this.sections.forEach(section => {
|
|
104
|
+
section.el.style.transform = "translate3d(0, 0, 0)"
|
|
105
|
+
const { top, bottom, offset } = this.getVars(section.el, section.speed)
|
|
106
|
+
Object.assign(section, { top, bottom, offset })
|
|
107
|
+
})
|
|
111
108
|
|
|
112
|
-
emitter.emit(EVENTS.APP_SMOOTH_RESIZE)
|
|
113
|
-
this.transformSections()
|
|
114
|
-
}
|
|
109
|
+
emitter.emit(EVENTS.APP_SMOOTH_RESIZE)
|
|
110
|
+
this.transformSections()
|
|
111
|
+
}
|
|
115
112
|
|
|
116
113
|
update(elems) {
|
|
117
|
-
kitStore.flags.isResizing = true
|
|
114
|
+
kitStore.flags.isResizing = true
|
|
118
115
|
|
|
119
|
-
this.scroll.setScrollBounds()
|
|
120
|
-
this.elems = elems || qsa("[data-smooth]")
|
|
121
|
-
this.scrollbar.update()
|
|
122
|
-
this.getSections()
|
|
123
|
-
this.transformSections()
|
|
116
|
+
this.scroll.setScrollBounds()
|
|
117
|
+
this.elems = elems || qsa("[data-smooth]")
|
|
118
|
+
this.scrollbar.update()
|
|
119
|
+
this.getSections()
|
|
120
|
+
this.transformSections()
|
|
124
121
|
|
|
125
|
-
kitStore.flags.isResizing = false
|
|
122
|
+
kitStore.flags.isResizing = false
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
clean() {
|
|
129
|
-
this.elems = this.sections = null
|
|
126
|
+
this.elems = this.sections = null
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
on() {
|
|
133
|
-
emitter.on(EVENTS.APP_TICK, this.tick)
|
|
134
|
-
emitter.on(EVENTS.APP_RESIZE, this.resize)
|
|
130
|
+
emitter.on(EVENTS.APP_TICK, this.tick)
|
|
131
|
+
emitter.on(EVENTS.APP_RESIZE, this.resize)
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
off() {
|
|
138
|
-
emitter.off(EVENTS.APP_TICK, this.tick)
|
|
139
|
-
emitter.off(EVENTS.APP_RESIZE, this.resize)
|
|
135
|
+
emitter.off(EVENTS.APP_TICK, this.tick)
|
|
136
|
+
emitter.off(EVENTS.APP_RESIZE, this.resize)
|
|
140
137
|
}
|
|
141
138
|
|
|
142
139
|
init(elems) {
|
|
143
|
-
this.elems = elems || qsa("[data-smooth]")
|
|
144
|
-
this.getSections()
|
|
145
|
-
this.scrollbar = new Scrollbar(
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
this.elems = elems || qsa("[data-smooth]")
|
|
141
|
+
this.getSections()
|
|
142
|
+
this.scrollbar = new Scrollbar({
|
|
143
|
+
container: kitStore.pageContent,
|
|
144
|
+
})
|
|
145
|
+
this.on()
|
|
146
|
+
this.update()
|
|
148
147
|
}
|
|
149
148
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { splitText, reverseSplit } from "@linear_non/stellar-kit/utils"
|
|
2
|
-
import { EVENTS } from "@linear_non/stellar-kit/events"
|
|
3
|
-
import { ScrollTrigger } from "@linear_non/stellar-kit/gsap"
|
|
1
|
+
import { splitText, reverseSplit } from "@linear_non/stellar-kit/utils"
|
|
2
|
+
import { EVENTS } from "@linear_non/stellar-kit/events"
|
|
3
|
+
import { ScrollTrigger } from "@linear_non/stellar-kit/gsap"
|
|
4
4
|
|
|
5
5
|
export default class SplitonScroll {
|
|
6
6
|
constructor({
|
|
@@ -13,19 +13,19 @@ export default class SplitonScroll {
|
|
|
13
13
|
scrub = false,
|
|
14
14
|
once = true,
|
|
15
15
|
}) {
|
|
16
|
-
this.element = el
|
|
17
|
-
this.splitText = splitText
|
|
18
|
-
this.splits = []
|
|
19
|
-
this.animateCallback = animate || (() => {})
|
|
20
|
-
this.reverseCallback = reverse || (() => {})
|
|
21
|
-
this.start = start
|
|
22
|
-
this.end = end
|
|
23
|
-
this.scrub = scrub
|
|
24
|
-
this.once = once
|
|
16
|
+
this.element = el
|
|
17
|
+
this.splitText = splitText
|
|
18
|
+
this.splits = []
|
|
19
|
+
this.animateCallback = animate || (() => {})
|
|
20
|
+
this.reverseCallback = reverse || (() => {})
|
|
21
|
+
this.start = start
|
|
22
|
+
this.end = end
|
|
23
|
+
this.scrub = scrub
|
|
24
|
+
this.once = once
|
|
25
25
|
|
|
26
|
-
if (!this.splitText[0]) return
|
|
26
|
+
if (!this.splitText[0]) return
|
|
27
27
|
|
|
28
|
-
this.initScrollTrigger()
|
|
28
|
+
this.initScrollTrigger()
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
initScrollTrigger() {
|
|
@@ -37,20 +37,20 @@ export default class SplitonScroll {
|
|
|
37
37
|
once: this.once,
|
|
38
38
|
onEnter: () => this.handleEnter(),
|
|
39
39
|
onLeave: () => this.handleLeave(),
|
|
40
|
-
})
|
|
40
|
+
})
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
handleEnter() {
|
|
44
|
-
const split = splitText(this.splitText)
|
|
45
|
-
split.on(EVENTS.APP_SPLITTEXT_READY,
|
|
46
|
-
this.splits = [...splits]
|
|
47
|
-
this.animateCallback([...splits])
|
|
48
|
-
})
|
|
44
|
+
const split = splitText(this.splitText)
|
|
45
|
+
split.on(EVENTS.APP_SPLITTEXT_READY, splits => {
|
|
46
|
+
this.splits = [...splits]
|
|
47
|
+
this.animateCallback([...splits])
|
|
48
|
+
})
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
handleLeave() {
|
|
52
|
-
reverseSplit(this.splits)
|
|
53
|
-
this.reverseCallback()
|
|
54
|
-
this.myScrollTrigger.kill()
|
|
52
|
+
reverseSplit(this.splits)
|
|
53
|
+
this.reverseCallback()
|
|
54
|
+
this.myScrollTrigger.kill()
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/Sticky/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
// Sticky.js
|
|
2
|
-
import { bounds } from "@linear_non/stellar-kit/utils"
|
|
3
|
-
import { gsap, ScrollTrigger } from "@linear_non/stellar-kit/gsap"
|
|
2
|
+
import { bounds } from "@linear_non/stellar-kit/utils"
|
|
3
|
+
import { gsap, ScrollTrigger } from "@linear_non/stellar-kit/gsap"
|
|
4
4
|
|
|
5
5
|
export default class Sticky {
|
|
6
6
|
constructor(obj) {
|
|
7
|
-
const { el, sticky, isSmooth, onUpdateCallback } = obj
|
|
8
|
-
|
|
9
|
-
this.el = el
|
|
10
|
-
this.sticky = sticky
|
|
11
|
-
this.isSticky = false
|
|
12
|
-
this.isSmooth = isSmooth
|
|
13
|
-
this.progress = 0
|
|
14
|
-
this.total = 0
|
|
15
|
-
this.positionX = 0
|
|
16
|
-
this.positionY = 0
|
|
17
|
-
this.scrollTrigger = null
|
|
18
|
-
this.onUpdateCallback =
|
|
19
|
-
typeof onUpdateCallback === "function" ? onUpdateCallback : null;
|
|
7
|
+
const { el, sticky, isSmooth, onUpdateCallback } = obj
|
|
8
|
+
|
|
9
|
+
this.el = el
|
|
10
|
+
this.sticky = sticky
|
|
11
|
+
this.isSticky = false
|
|
12
|
+
this.isSmooth = isSmooth
|
|
13
|
+
this.progress = 0
|
|
14
|
+
this.total = 0
|
|
15
|
+
this.positionX = 0
|
|
16
|
+
this.positionY = 0
|
|
17
|
+
this.scrollTrigger = null
|
|
18
|
+
this.onUpdateCallback = typeof onUpdateCallback === "function" ? onUpdateCallback : null
|
|
20
19
|
|
|
21
20
|
this.config = {
|
|
22
21
|
width: 0,
|
|
@@ -24,13 +23,13 @@ export default class Sticky {
|
|
|
24
23
|
totalWidth: 0,
|
|
25
24
|
totalHeight: 0,
|
|
26
25
|
totalItems: 0,
|
|
27
|
-
}
|
|
28
|
-
if (!isSmooth) sticky.style.pointerEvents = "none"
|
|
29
|
-
this.init()
|
|
26
|
+
}
|
|
27
|
+
if (!isSmooth) sticky.style.pointerEvents = "none"
|
|
28
|
+
this.init()
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
observer() {
|
|
33
|
-
if (this.scrollTrigger) this.scrollTrigger.kill()
|
|
32
|
+
if (this.scrollTrigger) this.scrollTrigger.kill() // Prevent duplicate listeners
|
|
34
33
|
|
|
35
34
|
this.scrollTrigger = ScrollTrigger.create({
|
|
36
35
|
trigger: this.el,
|
|
@@ -41,47 +40,41 @@ export default class Sticky {
|
|
|
41
40
|
onEnterBack: () => this.toggleSticky(true),
|
|
42
41
|
onLeave: () => this.toggleSticky(false, true), // ✅ Ensure totalHeight is passed
|
|
43
42
|
onLeaveBack: () => this.toggleSticky(false),
|
|
44
|
-
onUpdate:
|
|
45
|
-
})
|
|
43
|
+
onUpdate: self => this.onUpdate(self),
|
|
44
|
+
})
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
toggleSticky(isSticky, hasTotalHeight = false) {
|
|
49
|
-
this.isSticky = isSticky
|
|
50
|
-
isSticky
|
|
51
|
-
? this.addSticky()
|
|
52
|
-
: this.removeSticky(hasTotalHeight ? this.config.totalHeight : 0);
|
|
48
|
+
this.isSticky = isSticky
|
|
49
|
+
isSticky ? this.addSticky() : this.removeSticky(hasTotalHeight ? this.config.totalHeight : 0)
|
|
53
50
|
}
|
|
54
51
|
|
|
55
52
|
addSticky() {
|
|
56
|
-
if (!this.sticky || this.isSmooth) return
|
|
57
|
-
this.sticky.classList.add("-fixed")
|
|
58
|
-
gsap.set(this.sticky, { top: 0, position: "" })
|
|
53
|
+
if (!this.sticky || this.isSmooth) return
|
|
54
|
+
this.sticky.classList.add("-fixed")
|
|
55
|
+
gsap.set(this.sticky, { top: 0, position: "" })
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
removeSticky(totalHeight = 0) {
|
|
62
|
-
if (!this.sticky || this.isSmooth) return
|
|
63
|
-
this.sticky.classList.remove("-fixed")
|
|
64
|
-
gsap.set(this.sticky, { top: `${totalHeight}px`, position: "relative" })
|
|
59
|
+
if (!this.sticky || this.isSmooth) return
|
|
60
|
+
this.sticky.classList.remove("-fixed")
|
|
61
|
+
gsap.set(this.sticky, { top: `${totalHeight}px`, position: "relative" })
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
onUpdate(self) {
|
|
68
|
-
const { totalWidth, totalHeight } = this.config
|
|
69
|
-
const newProgress = self.progress
|
|
70
|
-
const newY = newProgress * totalHeight
|
|
71
|
-
const newX = -newProgress * totalWidth
|
|
65
|
+
const { totalWidth, totalHeight } = this.config
|
|
66
|
+
const newProgress = self.progress
|
|
67
|
+
const newY = newProgress * totalHeight
|
|
68
|
+
const newX = -newProgress * totalWidth
|
|
72
69
|
|
|
73
70
|
// Only update if values change to prevent unnecessary calls
|
|
74
|
-
if (
|
|
75
|
-
this.progress
|
|
76
|
-
this.positionY
|
|
77
|
-
this.positionX
|
|
78
|
-
) {
|
|
79
|
-
this.progress = newProgress;
|
|
80
|
-
this.positionY = newY;
|
|
81
|
-
this.positionX = newX;
|
|
71
|
+
if (this.progress !== newProgress || this.positionY !== newY || this.positionX !== newX) {
|
|
72
|
+
this.progress = newProgress
|
|
73
|
+
this.positionY = newY
|
|
74
|
+
this.positionX = newX
|
|
82
75
|
|
|
83
76
|
if (this.isSmooth) {
|
|
84
|
-
gsap.set(this.sticky, { y: this.positionY })
|
|
77
|
+
gsap.set(this.sticky, { y: this.positionY })
|
|
85
78
|
}
|
|
86
79
|
|
|
87
80
|
// Call the callback function if provided
|
|
@@ -90,34 +83,34 @@ export default class Sticky {
|
|
|
90
83
|
progress: this.progress,
|
|
91
84
|
positionX: this.positionX,
|
|
92
85
|
positionY: this.positionY,
|
|
93
|
-
})
|
|
86
|
+
})
|
|
94
87
|
}
|
|
95
88
|
}
|
|
96
89
|
}
|
|
97
90
|
|
|
98
91
|
resize() {
|
|
99
|
-
if (!this.sticky) return
|
|
92
|
+
if (!this.sticky) return
|
|
100
93
|
|
|
101
94
|
// Get the viewport height dynamically instead of using store
|
|
102
|
-
const vh = window.innerHeight
|
|
103
|
-
let stickyRect = bounds(this.el)
|
|
95
|
+
const vh = window.innerHeight
|
|
96
|
+
let stickyRect = bounds(this.el)
|
|
104
97
|
|
|
105
98
|
Object.assign(this.config, {
|
|
106
99
|
totalHeight: stickyRect.height - vh,
|
|
107
|
-
})
|
|
100
|
+
})
|
|
108
101
|
}
|
|
109
102
|
|
|
110
103
|
destroy() {
|
|
111
104
|
if (this.scrollTrigger) {
|
|
112
|
-
this.scrollTrigger.kill()
|
|
113
|
-
this.scrollTrigger = null
|
|
105
|
+
this.scrollTrigger.kill()
|
|
106
|
+
this.scrollTrigger = null
|
|
114
107
|
}
|
|
115
|
-
this.sticky = null
|
|
116
|
-
this.el = null
|
|
108
|
+
this.sticky = null
|
|
109
|
+
this.el = null
|
|
117
110
|
}
|
|
118
111
|
|
|
119
112
|
init() {
|
|
120
|
-
this.resize()
|
|
121
|
-
this.observer()
|
|
113
|
+
this.resize()
|
|
114
|
+
this.observer()
|
|
122
115
|
}
|
|
123
116
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Sticky from "./Sticky"
|
|
2
|
-
import Smooth from "./Smooth"
|
|
3
|
-
import SplitonScroll from "./SplitOnScroll"
|
|
1
|
+
import Sticky from "./Sticky"
|
|
2
|
+
import Smooth from "./Smooth"
|
|
3
|
+
import SplitonScroll from "./SplitOnScroll"
|
|
4
4
|
|
|
5
|
-
export { Sticky, Smooth, SplitonScroll }
|
|
5
|
+
export { Sticky, Smooth, SplitonScroll }
|