Add overflow exception to buttons

This commit is contained in:
Cooper Ransom 2024-04-04 10:44:30 -04:00
parent 249a527a9a
commit 2655154ce9
1 changed files with 16 additions and 1 deletions

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" });
}