mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-01 16:37:39 +01:00
Fix scrolling bug
This commit is contained in:
parent
a2b39ee288
commit
af74657f1a
1 changed files with 13 additions and 1 deletions
|
@ -197,14 +197,22 @@ export function Discover() {
|
||||||
}
|
}
|
||||||
}, [movieWidth]); // Added movieWidth to the dependency array
|
}, [movieWidth]); // Added movieWidth to the dependency array
|
||||||
|
|
||||||
|
let isScrolling = false;
|
||||||
|
|
||||||
function handleWheel(e: React.WheelEvent, categorySlug: string) {
|
function handleWheel(e: React.WheelEvent, categorySlug: string) {
|
||||||
|
if (isScrolling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isScrolling = true;
|
||||||
|
|
||||||
const carousel = carouselRefs.current[categorySlug];
|
const carousel = carouselRefs.current[categorySlug];
|
||||||
if (carousel) {
|
if (carousel) {
|
||||||
const movieElements = carousel.getElementsByTagName("a");
|
const movieElements = carousel.getElementsByTagName("a");
|
||||||
if (movieElements.length > 0) {
|
if (movieElements.length > 0) {
|
||||||
const posterWidth = movieElements[0].offsetWidth;
|
const posterWidth = movieElements[0].offsetWidth;
|
||||||
const visibleMovies = Math.floor(carousel.offsetWidth / posterWidth);
|
const visibleMovies = Math.floor(carousel.offsetWidth / posterWidth);
|
||||||
const scrollAmount = posterWidth * visibleMovies * 0.625;
|
const scrollAmount = posterWidth * visibleMovies * 0.6;
|
||||||
if (e.deltaY < 5) {
|
if (e.deltaY < 5) {
|
||||||
carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" });
|
carousel.scrollBy({ left: -scrollAmount, behavior: "smooth" });
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,6 +220,10 @@ export function Discover() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
isScrolling = false;
|
||||||
|
}, 345); // Disable scrolling every 3 milliseconds after interaction (only for mouse wheel doe)
|
||||||
}
|
}
|
||||||
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
Loading…
Reference in a new issue