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