fix: require click for card before-after slider and restore horizontal showcase scroll
This commit is contained in:
@@ -42,44 +42,10 @@ export function CinematicHorizontalScrollSection({
|
||||
const containerRef = useRef<HTMLElement>(null);
|
||||
const trackRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const targetXRef = useRef(0);
|
||||
const currentXRef = useRef(0);
|
||||
const animFrameRef = useRef<number>(0);
|
||||
const isLoopRunningRef = useRef(false);
|
||||
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const [canScrollLeft, setCanScrollLeft] = useState(false);
|
||||
const [canScrollRight, setCanScrollRight] = useState(true);
|
||||
|
||||
// High-performance, responsive LERP animation loop to smooth wheel notches into liquid momentum
|
||||
const startLerpLoop = useCallback(() => {
|
||||
if (isLoopRunningRef.current) return;
|
||||
isLoopRunningRef.current = true;
|
||||
|
||||
const loop = () => {
|
||||
const track = trackRef.current;
|
||||
if (!track) {
|
||||
isLoopRunningRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const diff = targetXRef.current - currentXRef.current;
|
||||
|
||||
if (Math.abs(diff) > 0.4) {
|
||||
// Responsive 0.28 damping factor: silky smoothing with zero perceptible lag
|
||||
currentXRef.current += diff * 0.28;
|
||||
track.style.transform = `translate3d(-${currentXRef.current.toFixed(2)}px, 0, 0)`;
|
||||
animFrameRef.current = requestAnimationFrame(loop);
|
||||
} else {
|
||||
currentXRef.current = targetXRef.current;
|
||||
track.style.transform = `translate3d(-${currentXRef.current.toFixed(2)}px, 0, 0)`;
|
||||
isLoopRunningRef.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
animFrameRef.current = requestAnimationFrame(loop);
|
||||
}, []);
|
||||
|
||||
// Compute fluid horizontal translation directly from vertical scroll progress
|
||||
const updateTranslation = useCallback(() => {
|
||||
const container = containerRef.current;
|
||||
@@ -102,8 +68,8 @@ export function CinematicHorizontalScrollSection({
|
||||
const lastCenter = cards[cards.length - 1].offsetLeft + cards[cards.length - 1].offsetWidth / 2;
|
||||
const maxDistance = lastCenter - firstCenter;
|
||||
|
||||
targetXRef.current = progress * maxDistance;
|
||||
startLerpLoop();
|
||||
const translateX = progress * maxDistance;
|
||||
track.style.transform = `translate3d(-${translateX.toFixed(2)}px, 0, 0)`;
|
||||
|
||||
// Sync active card index and button states
|
||||
const active = Math.min(
|
||||
@@ -114,21 +80,66 @@ export function CinematicHorizontalScrollSection({
|
||||
|
||||
setCanScrollLeft(progress > 0.02);
|
||||
setCanScrollRight(progress < 0.98);
|
||||
}, [startLerpLoop]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
|
||||
const handleScroll = () => {
|
||||
updateTranslation();
|
||||
};
|
||||
|
||||
// Support horizontal trackpad swipe (deltaX) on the showcase container
|
||||
const handleWheel = (e: WheelEvent) => {
|
||||
if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 6) {
|
||||
e.preventDefault();
|
||||
window.scrollBy({ top: e.deltaX * 1.2, behavior: 'auto' });
|
||||
}
|
||||
};
|
||||
|
||||
// Support touch horizontal swipe on mobile / tablet screens
|
||||
let touchStartX = 0;
|
||||
let touchStartY = 0;
|
||||
let initialScrollY = 0;
|
||||
|
||||
const handleTouchStart = (e: TouchEvent) => {
|
||||
if (!e.touches[0]) return;
|
||||
touchStartX = e.touches[0].clientX;
|
||||
touchStartY = e.touches[0].clientY;
|
||||
initialScrollY = window.scrollY;
|
||||
};
|
||||
|
||||
const handleTouchMove = (e: TouchEvent) => {
|
||||
if (!e.touches[0]) return;
|
||||
const deltaX = touchStartX - e.touches[0].clientX;
|
||||
const deltaY = touchStartY - e.touches[0].clientY;
|
||||
|
||||
if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > 10) {
|
||||
window.scrollTo({
|
||||
top: initialScrollY + deltaX * 1.3,
|
||||
behavior: 'auto',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
updateTranslation();
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
window.addEventListener('resize', handleScroll);
|
||||
|
||||
if (container) {
|
||||
container.addEventListener('wheel', handleWheel, { passive: false });
|
||||
container.addEventListener('touchstart', handleTouchStart, { passive: true });
|
||||
container.addEventListener('touchmove', handleTouchMove, { passive: true });
|
||||
}
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('scroll', handleScroll);
|
||||
window.removeEventListener('resize', handleScroll);
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
if (container) {
|
||||
container.removeEventListener('wheel', handleWheel);
|
||||
container.removeEventListener('touchstart', handleTouchStart);
|
||||
container.removeEventListener('touchmove', handleTouchMove);
|
||||
}
|
||||
};
|
||||
}, [updateTranslation, items.length]);
|
||||
|
||||
@@ -226,7 +237,7 @@ export function CinematicHorizontalScrollSection({
|
||||
style={{
|
||||
paddingLeft: 'calc((100vw - min(780px, 88vw)) / 2)',
|
||||
paddingRight: 'calc((100vw - min(780px, 88vw)) / 2)',
|
||||
transform: 'translate3d(0px, 0px, 0px)',
|
||||
transition: 'transform 0.08s cubic-bezier(0.25, 1, 0.5, 1)',
|
||||
}}
|
||||
>
|
||||
{items.map((item) => (
|
||||
|
||||
@@ -47,6 +47,11 @@ interface SectionRendererProps {
|
||||
}
|
||||
|
||||
export function SectionRenderer(props: SectionRendererProps) {
|
||||
// Sticky scroll-linked sections must not have parent transforms or content-visibility containment
|
||||
if (props.section.type === 'majorToolBanners' || props.section.type === 'cinematicHorizontal') {
|
||||
return <SectionContent {...props} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<SectionEntrance id={props.section.id}>
|
||||
<SectionContent {...props} />
|
||||
|
||||
Reference in New Issue
Block a user