Loading...
실무에서 쓰는 UI·UX·폼 패턴을 브라우저에서 바로 돌려보는 공간입니다
실험실
무한 스크롤 구현 패턴
1const observer = new IntersectionObserver(
2 (entries) => {
3 entries.forEach((entry) => {
4 if (entry.isIntersecting) {
5 // 요소가 뷰포트에 들어왔을 때
6 console.log("보임!");
7 }
8 });
9 },
10 {
11 threshold: 0.8, // 80% 이상 보일 때 콜백 실행
12 rootMargin: "0px", // 뷰포트 여백 조정
13 },
14);
15
16// 관찰 시작
17observer.observe(targetElement);
18
19// 관찰 중단 (컴포넌트 언마운트 시 정리)
20observer.unobserve(targetElement);
21observer.disconnect();