@linear_non/stellar-libs 1.0.18 → 1.0.19
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/Smooth/index.js +36 -12
package/package.json
CHANGED
package/src/Smooth/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export default class Smooth {
|
|
|
10
10
|
this.el = qs("[data-view]")
|
|
11
11
|
this.elems = null
|
|
12
12
|
this.current = 0
|
|
13
|
-
this.threshold = 100
|
|
14
13
|
this.sections = null
|
|
15
14
|
this.scrollbar = null
|
|
16
15
|
this.dpr = Math.max(1, Math.round(window.devicePixelRatio || 1))
|
|
@@ -22,10 +21,20 @@ export default class Smooth {
|
|
|
22
21
|
if (!this.elems || !isSmooth) return
|
|
23
22
|
|
|
24
23
|
this.sections = []
|
|
24
|
+
let cursor = 0
|
|
25
|
+
let max = 0
|
|
26
|
+
|
|
25
27
|
this.elems.forEach(el => {
|
|
26
28
|
el.style.transform = "translate3d(0, 0, 0)"
|
|
27
29
|
const speed = el.dataset.speed || 1
|
|
28
|
-
const {
|
|
30
|
+
const { height, offset } = this.getVars(el, speed)
|
|
31
|
+
|
|
32
|
+
const top = cursor
|
|
33
|
+
const bottom = top + height
|
|
34
|
+
|
|
35
|
+
cursor = bottom
|
|
36
|
+
max = bottom
|
|
37
|
+
|
|
29
38
|
let parent = el.parentNode.closest("[data-smooth]")
|
|
30
39
|
|
|
31
40
|
if (parent) {
|
|
@@ -74,9 +83,11 @@ export default class Smooth {
|
|
|
74
83
|
const extra = (parent && parent.transform) || 0
|
|
75
84
|
const translate = this.current * speed
|
|
76
85
|
const transform = translate - offset - extra
|
|
86
|
+
|
|
77
87
|
const start = top - translate
|
|
78
88
|
const end = bottom - translate
|
|
79
|
-
|
|
89
|
+
|
|
90
|
+
const isVisible = end > 0 && start < vh
|
|
80
91
|
|
|
81
92
|
return { isVisible, transform }
|
|
82
93
|
}
|
|
@@ -90,12 +101,13 @@ export default class Smooth {
|
|
|
90
101
|
getVars(el, speed) {
|
|
91
102
|
const { vh } = kitStore.sizes
|
|
92
103
|
const rect = bounds(el)
|
|
93
|
-
const
|
|
104
|
+
const height = rect.height
|
|
105
|
+
|
|
106
|
+
const centering = vh / 2 - height / 2
|
|
94
107
|
const offset = rect.top < vh ? 0 : (rect.top - centering) * speed - (rect.top - centering)
|
|
95
108
|
|
|
96
109
|
return {
|
|
97
|
-
|
|
98
|
-
bottom: rect.bottom + offset,
|
|
110
|
+
height,
|
|
99
111
|
offset,
|
|
100
112
|
}
|
|
101
113
|
}
|
|
@@ -103,9 +115,19 @@ export default class Smooth {
|
|
|
103
115
|
resize = () => {
|
|
104
116
|
if (!this.sections) return
|
|
105
117
|
|
|
118
|
+
let cursor = 0
|
|
119
|
+
let max = 0
|
|
120
|
+
|
|
106
121
|
this.sections.forEach(section => {
|
|
107
122
|
section.el.style.transform = "translate3d(0, 0, 0)"
|
|
108
|
-
const {
|
|
123
|
+
const { height, offset } = this.getVars(section.el, section.speed)
|
|
124
|
+
|
|
125
|
+
const top = cursor
|
|
126
|
+
const bottom = top + height
|
|
127
|
+
|
|
128
|
+
cursor = bottom
|
|
129
|
+
max = bottom
|
|
130
|
+
|
|
109
131
|
Object.assign(section, { top, bottom, offset })
|
|
110
132
|
})
|
|
111
133
|
|
|
@@ -131,9 +153,11 @@ export default class Smooth {
|
|
|
131
153
|
emitter.on(EVENTS.APP_TICK, this.tick)
|
|
132
154
|
emitter.on(EVENTS.APP_RESIZE, this.resize)
|
|
133
155
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
156
|
+
if (document.readyState === "complete") {
|
|
157
|
+
this.update()
|
|
158
|
+
} else {
|
|
159
|
+
window.addEventListener("load", () => this.update(), { once: true })
|
|
160
|
+
}
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
off() {
|
|
@@ -143,11 +167,11 @@ export default class Smooth {
|
|
|
143
167
|
|
|
144
168
|
init(elems) {
|
|
145
169
|
this.elems = elems || qsa("[data-smooth]")
|
|
146
|
-
|
|
170
|
+
|
|
147
171
|
this.scrollbar = new Scrollbar({
|
|
148
172
|
container: kitStore.currentPage,
|
|
149
173
|
})
|
|
174
|
+
|
|
150
175
|
this.on()
|
|
151
|
-
this.update()
|
|
152
176
|
}
|
|
153
177
|
}
|