1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

Add overflow exception to buttons

This commit is contained in:
Cooper Ransom 2024-04-04 10:44:30 -04:00
parent 249a527a9a
commit 2655154ce9

View file

@ -165,7 +165,22 @@ export function Discover() {
const visibleMovies = Math.floor(carousel.offsetWidth / movieWidth);
const scrollAmount = movieWidth * visibleMovies;
if (direction === "left") {
carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" });
if (carousel.scrollLeft <= 5) {
carousel.scrollBy({
left: carousel.scrollWidth,
behavior: "smooth",
}); // Scroll to the end
} else {
carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" });
}
} else if (
carousel.scrollLeft + carousel.offsetWidth + 5 >=
carousel.scrollWidth
) {
carousel.scrollBy({
left: -carousel.scrollWidth,
behavior: "smooth",
}); // Scroll to the beginning
} else {
carousel.scrollBy({ left: scrollAmount, behavior: "smooth" });
}