fix: make sure setActiveImage gets integer value after scroll

This commit is contained in:
Sebin Nyshkim 2023-01-25 19:28:54 +01:00
parent a0182fe447
commit 6b0acce446

View file

@ -49,7 +49,9 @@ const next = (): void => {
};
const onScroll = (): void => {
const newImg = getActiveImage(galleryViewport.value, galleryItemWidth.value);
const newImg = Math.floor(
getActiveImage(galleryViewport.value, galleryItemWidth.value)
);
setActiveImage(newImg);
};
@ -58,7 +60,7 @@ onMounted(() => {
images.value = Array.from(galleryViewport.value.children);
galleryItemWidth.value =
galleryViewport.value.scrollWidth / images.value.length;
galleryViewport.value.addEventListener("scroll", debounce(onScroll, 100));
galleryViewport.value.addEventListener("scroll", debounce(onScroll, 500));
});
</script>