상세 컨텐츠

본문 제목

React 특정 엘리먼트로 스크롤 이동

웹개발/프론트엔드

by 구스만 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>
    );
}

 

 

 

관련글 더보기