Improve video carousel scrolling by using native scroll functionality
Refactors the `CategoryRow` component in `netflix-grid.tsx` to utilize the browser's native `scrollBy` method for smoother and more performant horizontal scrolling of video categories, replacing the previous manual translation logic. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2eb1084e-b728-4449-9231-f1665924c8d5 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2eb1084e-b728-4449-9231-f1665924c8d5/yexZbDm
This commit is contained in:
parent
91617c8835
commit
95cc839838
BIN
attached_assets/image_1756487569961.png
Normal file
BIN
attached_assets/image_1756487569961.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
@ -164,25 +164,15 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
|
||||
const interval = 16; // Fixed interval - speed controlled by pixel movement only
|
||||
|
||||
scrollIntervalRef.current = setInterval(() => {
|
||||
setTranslateX(prev => {
|
||||
// Use the NEW speed that was just set
|
||||
const currentSpeed = newSpeed === 'fast' ? 3.5 : 2.0;
|
||||
const speed = direction === 'right' ? -currentSpeed : currentSpeed;
|
||||
const newX = prev + speed;
|
||||
const totalWidth = category.videos.length * videoWidth;
|
||||
|
||||
// TRUE INFINITE SCROLL - wrap around seamlessly
|
||||
if (direction === 'right' && newX <= -totalWidth) {
|
||||
// When moved one full cycle to the right, wrap back to start
|
||||
return newX + totalWidth;
|
||||
} else if (direction === 'left' && newX >= totalWidth) {
|
||||
// When moved one full cycle to the left, wrap back to end
|
||||
return newX - totalWidth;
|
||||
}
|
||||
|
||||
return newX;
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const currentSpeed = newSpeed === 'fast' ? 5 : 2;
|
||||
const scrollAmount = direction === 'right' ? currentSpeed : -currentSpeed;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'auto'
|
||||
});
|
||||
}, interval);
|
||||
}, 16);
|
||||
}
|
||||
};
|
||||
|
||||
@ -196,33 +186,20 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) {
|
||||
|
||||
// Start continuous smooth scrolling with variable speed
|
||||
scrollIntervalRef.current = setInterval(() => {
|
||||
setTranslateX(prev => {
|
||||
// Faster speed for better movement
|
||||
const baseSpeed = 2.0; // Faster speed on hover
|
||||
const speed = direction === 'right' ? -baseSpeed : baseSpeed;
|
||||
const newX = prev + speed;
|
||||
const totalWidth = category.videos.length * videoWidth;
|
||||
|
||||
// TRUE INFINITE SCROLL - wrap around seamlessly
|
||||
if (direction === 'right' && newX <= -totalWidth) {
|
||||
// When moved one full cycle to the right, wrap back to start
|
||||
return newX + totalWidth;
|
||||
} else if (direction === 'left' && newX >= totalWidth) {
|
||||
// When moved one full cycle to the left, wrap back to end
|
||||
return newX - totalWidth;
|
||||
}
|
||||
|
||||
return newX;
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const baseSpeed = 3; // Faster speed on hover
|
||||
const scrollAmount = direction === 'right' ? baseSpeed : -baseSpeed;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'auto'
|
||||
});
|
||||
}, 16); // Fixed interval - speed controlled by pixel movement only
|
||||
}, 16);
|
||||
};
|
||||
|
||||
// Initialize with first video on the left side
|
||||
useEffect(() => {
|
||||
if (category.videos.length > 0) {
|
||||
// Start at position 0
|
||||
setTranslateX(0);
|
||||
}
|
||||
// No need to set initial position for scroll - browser handles it
|
||||
}, [category.videos.length]);
|
||||
|
||||
// Always show both buttons
|
||||
|
||||
Loading…
Reference in New Issue
Block a user