@linear_non/stellar-libs 1.0.19 → 1.0.21
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/SplitOnScroll/index.js +34 -11
package/package.json
CHANGED
|
@@ -14,8 +14,21 @@ export default class SplitonScroll {
|
|
|
14
14
|
once = true,
|
|
15
15
|
}) {
|
|
16
16
|
this.element = el
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
if (!splitText) {
|
|
19
|
+
this.targets = []
|
|
20
|
+
} else if (splitText instanceof Element) {
|
|
21
|
+
this.targets = [splitText]
|
|
22
|
+
} else if (Array.isArray(splitText)) {
|
|
23
|
+
this.targets = splitText
|
|
24
|
+
} else {
|
|
25
|
+
this.targets = Array.from(splitText)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!this.targets.length) return
|
|
29
|
+
|
|
30
|
+
this.splits = null
|
|
31
|
+
|
|
19
32
|
this.animateCallback = animate || (() => {})
|
|
20
33
|
this.reverseCallback = reverse || (() => {})
|
|
21
34
|
this.start = start
|
|
@@ -23,10 +36,7 @@ export default class SplitonScroll {
|
|
|
23
36
|
this.scrub = scrub
|
|
24
37
|
this.once = once
|
|
25
38
|
|
|
26
|
-
if (!this.splitText[0]) return
|
|
27
|
-
|
|
28
39
|
// this.initScrollTrigger()
|
|
29
|
-
|
|
30
40
|
this.addObserver()
|
|
31
41
|
}
|
|
32
42
|
|
|
@@ -49,23 +59,32 @@ export default class SplitonScroll {
|
|
|
49
59
|
end: this.end,
|
|
50
60
|
scrub: this.scrub,
|
|
51
61
|
})
|
|
62
|
+
|
|
52
63
|
this.observer.on("enter", () => this.handleEnter())
|
|
53
64
|
this.observer.on("leave", () => this.handleLeave())
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
handleEnter() {
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
const split = splitText(this.targets)
|
|
69
|
+
|
|
59
70
|
split.on(EVENTS.APP_SPLITTEXT_READY, splits => {
|
|
60
|
-
this.splits =
|
|
61
|
-
this.
|
|
71
|
+
this.splits = splits
|
|
72
|
+
this.hasSplit = true
|
|
73
|
+
|
|
74
|
+
this.animateCallback(this.splits)
|
|
62
75
|
})
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
handleLeave() {
|
|
66
|
-
|
|
79
|
+
if (this.splits) {
|
|
80
|
+
reverseSplit(this.splits)
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
this.reverseCallback()
|
|
68
|
-
|
|
84
|
+
|
|
85
|
+
if (this.once) {
|
|
86
|
+
this.destroy()
|
|
87
|
+
}
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
update() {
|
|
@@ -74,5 +93,9 @@ export default class SplitonScroll {
|
|
|
74
93
|
|
|
75
94
|
destroy() {
|
|
76
95
|
this.observer?.kill()
|
|
96
|
+
|
|
97
|
+
this.splits = null
|
|
98
|
+
this.targets = null
|
|
99
|
+
this.element = null
|
|
77
100
|
}
|
|
78
101
|
}
|