Skip to content

Commit

Permalink
fix: 이미지 스크롤 버그
Browse files Browse the repository at this point in the history
  • Loading branch information
wildcatco committed Aug 3, 2023
1 parent 5630b26 commit 147cc64
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/pages/feed/PostDetail/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,31 @@ export function PostDetailContent({
images?: string[] | null;
}) {
const [zoomedImageIndex, setZoomedImageIndex] = useState<number | null>(null);
const multipleImagesRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (!multipleImagesRef.current) return;

const allImages =
multipleImagesRef.current?.querySelectorAll<HTMLImageElement>('img');
Promise.all(
Array.from(allImages)
.filter((img) => !img.complete)
.map(
(img) =>
new Promise((resolve) => {
img.onload = img.onerror = resolve;
})
)
).then(() => {
if (multipleImagesRef.current) {
multipleImagesRef.current.scrollTo({
left: 0,
});
multipleImagesRef.current.style.opacity = '1';
}
});
}, [multipleImagesRef.current]);

return (
<div>
Expand All @@ -276,7 +301,8 @@ export function PostDetailContent({
)}
{images && images.length > 1 && (
<div
className="flex space-x-[1.3rem] overflow-x-auto px-[1.5rem]"
ref={multipleImagesRef}
className="flex space-x-[1.3rem] overflow-x-auto px-[1.5rem] opacity-0"
style={{
scrollSnapType: 'x mandatory',
}}
Expand Down

0 comments on commit 147cc64

Please sign in to comment.