Skip to content

Commit

Permalink
Misc: Clearer that it is a album slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmevik committed Oct 3, 2024
1 parent d94b788 commit db1b800
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/components/Slideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ function Slideshow({ className }: { className?: string }) {
onTouchMove,
} = useSlideshow(trackRef);


return (
<div
style={{ willChange: "transform" }}
className={twMerge(
"absolute top-1/2 left-1/2 -translate-y-1/2",
"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",
className
)}
onMouseDown={(e) => onMouseDown(e.clientX)}
Expand Down Expand Up @@ -74,7 +73,7 @@ function ImageSlide({ src, alt }: { src: string; alt: string }) {
<img
width={1280}
height={720}
style={{ objectPosition: "100% center", willChange: "transform" }}
style={{ objectPosition: "50% center", willChange: "transform" }}
className="aspect-[5/7] w-[80vmin] object-cover sm:w-[40vmin]"
src={src}
alt={alt}
Expand Down
11 changes: 9 additions & 2 deletions src/hooks/useSlideShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ function animateTrack(track: HTMLDivElement, nextPercentage: number) {
function animateImages(images: HTMLImageElement[]) {
for (const image of images) {
const { right, left } = image.getBoundingClientRect();
/*
if (right < 0 || left > window.innerWidth) {
continue; // Skip images not in viewport
}*/

if (right < -image.width || left > window.innerWidth + image.width) {
continue; // Skip images not in viewport
}

updateImageObjectPosition(image);
}
}
Expand Down Expand Up @@ -78,6 +84,7 @@ function useSlideshow(trackRef: React.RefObject<HTMLDivElement>) {
resizeRAFId = null;
});
};
handleResize();

window.addEventListener("resize", handleResize);
return () => {
Expand All @@ -97,8 +104,8 @@ function useSlideshow(trackRef: React.RefObject<HTMLDivElement>) {
const maxDelta = curr.clientWidth / 2;
const percentage = (delta / maxDelta) * -100;
return Math.max(
Math.min(prevSlide.current + percentage, 0),
-100
Math.min(prevSlide.current + percentage, 50),
-50
);
}

Expand Down

0 comments on commit db1b800

Please sign in to comment.