웹개발/프론트엔드
React 특정 엘리먼트로 스크롤 이동
구스만
2024. 9. 13. 16:06
특정 엘리먼트로 스크롤 이동시키는 방법
function Component() {
const componentRef = useRef(null);
const moveScroll = () => {
componentRef.current?.scrollIntoView({
behavior: "smooth"
})
}
return (
<div ref={componentRef}>스크롤 타겟 엘리먼트</div>
<button onClick={() => moveScroll}>스크롤 이동</button>
);
}