Improve carousel scrolling speed and responsiveness
Update the SimpleCarousel component to allow immediate speed changes and initialize scrolling with a defined speed value. 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
c3ec76860a
commit
e377b33f7b
@ -24,16 +24,16 @@ export default function SimpleCarousel({ category, onVideoClick }: SimpleCarouse
|
||||
const newSpeed = speed === 'normal' ? 'fast' : 'normal';
|
||||
setSpeed(newSpeed);
|
||||
|
||||
// Restart with new speed
|
||||
// Restart with new speed immediately
|
||||
if (scrollIntervalRef.current) {
|
||||
clearInterval(scrollIntervalRef.current);
|
||||
}
|
||||
|
||||
const speedValue = newSpeed === 'fast' ? 1.2 : 0.6;
|
||||
scrollIntervalRef.current = setInterval(() => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const currentSpeed = newSpeed === 'fast' ? 1.2 : 0.6;
|
||||
const scrollAmount = direction === 'right' ? currentSpeed : -currentSpeed;
|
||||
const scrollAmount = direction === 'right' ? speedValue : -speedValue;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'auto'
|
||||
@ -54,11 +54,11 @@ export default function SimpleCarousel({ category, onVideoClick }: SimpleCarouse
|
||||
setCurrentDirection(direction);
|
||||
setSpeed('normal'); // Reset to normal speed when starting
|
||||
|
||||
const speedValue = 0.6; // Always start with normal speed
|
||||
scrollIntervalRef.current = setInterval(() => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const currentSpeed = speed === 'fast' ? 1.2 : 0.6;
|
||||
const scrollAmount = direction === 'right' ? currentSpeed : -currentSpeed;
|
||||
const scrollAmount = direction === 'right' ? speedValue : -speedValue;
|
||||
scrollContainerRef.current.scrollBy({
|
||||
left: scrollAmount,
|
||||
behavior: 'auto'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user