@woylie/doggo 0.15.0 → 0.15.1
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/README.md +1 -1
- package/assets/js/hooks/carousel.js +21 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,11 +83,17 @@ export function initCarousel(carousel) {
|
|
|
83
83
|
|
|
84
84
|
const syncActiveState = () => setActiveIdx(getActiveIdx());
|
|
85
85
|
|
|
86
|
+
const SCROLL_SETTLE_MS = 100;
|
|
87
|
+
|
|
88
|
+
let pendingIdx = null;
|
|
89
|
+
let settleTimer = null;
|
|
90
|
+
|
|
86
91
|
const scrollToIdx = (idx) => {
|
|
87
92
|
const item = getItems()[idx];
|
|
88
93
|
|
|
89
94
|
if (!item) return;
|
|
90
95
|
|
|
96
|
+
pendingIdx = idx;
|
|
91
97
|
setActiveIdx(idx);
|
|
92
98
|
|
|
93
99
|
const itemsContainer = getItemsContainer();
|
|
@@ -190,7 +196,15 @@ export function initCarousel(carousel) {
|
|
|
190
196
|
carousel.addEventListener(
|
|
191
197
|
"scroll",
|
|
192
198
|
(e) => {
|
|
193
|
-
if (e.target
|
|
199
|
+
if (e.target !== getItemsContainer()) return;
|
|
200
|
+
|
|
201
|
+
clearTimeout(settleTimer);
|
|
202
|
+
settleTimer = setTimeout(() => {
|
|
203
|
+
pendingIdx = null;
|
|
204
|
+
syncActiveState();
|
|
205
|
+
}, SCROLL_SETTLE_MS);
|
|
206
|
+
|
|
207
|
+
if (pendingIdx === null) syncActiveState();
|
|
194
208
|
},
|
|
195
209
|
true,
|
|
196
210
|
);
|
|
@@ -295,7 +309,12 @@ export function initCarousel(carousel) {
|
|
|
295
309
|
}
|
|
296
310
|
};
|
|
297
311
|
|
|
298
|
-
|
|
312
|
+
const destroy = () => {
|
|
313
|
+
stopAutoRotation();
|
|
314
|
+
clearTimeout(settleTimer);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
return { update: syncAfterUpdate, destroy };
|
|
299
318
|
}
|
|
300
319
|
|
|
301
320
|
export default {
|