mirror of
https://github.com/DavidHDev/vue-bits.git
synced 2026-03-07 22:49:31 -07:00
fix: refactor watch logic for manual mode and animation duration in TrueFocus component
This commit is contained in:
@@ -31,26 +31,6 @@ const focusRect = ref({ x: 0, y: 0, width: 0, height: 0 });
|
|||||||
|
|
||||||
let interval: number | null = null;
|
let interval: number | null = null;
|
||||||
|
|
||||||
watch(
|
|
||||||
[() => props.manualMode, () => props.animationDuration, () => props.pauseBetweenAnimations, () => words.value],
|
|
||||||
() => {
|
|
||||||
if (interval) {
|
|
||||||
clearInterval(interval);
|
|
||||||
interval = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!props.manualMode) {
|
|
||||||
interval = setInterval(
|
|
||||||
() => {
|
|
||||||
currentIndex.value = (currentIndex.value + 1) % words.value.length;
|
|
||||||
},
|
|
||||||
(props.animationDuration + props.pauseBetweenAnimations) * 1000
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[currentIndex, () => words.value.length],
|
[currentIndex, () => words.value.length],
|
||||||
async () => {
|
async () => {
|
||||||
@@ -105,6 +85,26 @@ onMounted(async () => {
|
|||||||
height: activeRect.height
|
height: activeRect.height
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
[() => props.manualMode, () => props.animationDuration, () => props.pauseBetweenAnimations, () => words.value],
|
||||||
|
() => {
|
||||||
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
interval = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!props.manualMode) {
|
||||||
|
interval = setInterval(
|
||||||
|
() => {
|
||||||
|
currentIndex.value = (currentIndex.value + 1) % words.value.length;
|
||||||
|
},
|
||||||
|
(props.animationDuration + props.pauseBetweenAnimations) * 1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user