Skip to content

Commit e22c47f

Browse files
committed
Improvement - VueUiCarouselTable - Add marquee type animation option
1 parent 66b57ed commit e22c47f

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/components/vue-ui-carousel-table.vue

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ function toggleFullscreen(state) {
196196
197197
function startAnimation() {
198198
if (!raf.value && !isPaused.value) {
199-
raf.value = requestAnimationFrame(animate);
199+
if (FINAL_CONFIG.value.animation.type === 'scroll') {
200+
raf.value = requestAnimationFrame(animate);
201+
} else {
202+
raf.value = requestAnimationFrame(animateMarquee);
203+
}
200204
}
201205
}
202206
@@ -233,6 +237,29 @@ function animate(timestamp) {
233237
raf.value = requestAnimationFrame(animate);
234238
}
235239
240+
function animateMarquee(timestamp) {
241+
if (isPaused.value) return;
242+
if (!lastTimestamp.value) lastTimestamp.value = timestamp;
243+
244+
const deltaTime = timestamp - lastTimestamp.value;
245+
const marqueeSpeed = (FINAL_CONFIG.value.animation.speedMs / 4) / 1000;
246+
247+
if (deltaTime >= marqueeSpeed) {
248+
init.value += marqueeSpeed;
249+
if (init.value >= (tableContainer.value.scrollHeight - tableContainer.value.clientHeight)) {
250+
init.value = 0;
251+
}
252+
if (tableContainer.value) {
253+
tableContainer.value.scrollTo({
254+
top: init.value,
255+
behavior: 'auto',
256+
});
257+
}
258+
lastTimestamp.value = timestamp;
259+
}
260+
raf.value = requestAnimationFrame(animateMarquee);
261+
}
262+
236263
function pauseAnimation() {
237264
isPaused.value = true;
238265
cancelAnimationFrame(raf.value);
@@ -278,6 +305,20 @@ watch(
278305
}
279306
);
280307
308+
watch(
309+
() => FINAL_CONFIG.value.animation.type,
310+
(_newVal) => {
311+
pauseAnimation();
312+
init.value = 0;
313+
scrollIndex.value = 0;
314+
tableContainer.value.scrollTo({
315+
top: 0,
316+
behavior: 'auto',
317+
});
318+
resumeAnimation();
319+
}
320+
);
321+
281322
const breakpoint = computed(() => FINAL_CONFIG.value.responsiveBreakpoint);
282323
283324
onMounted(() => {

0 commit comments

Comments
 (0)