본문 바로가기
Front-End/Javascript

Element: scrollIntoView()

by sharekim 2023. 12. 5.

이벤트나 상태변화에 따라 어떤 Element 로 상위 엘리먼트의 스크롤을 이동하고자 할 때 사용하는 메서드이다.

 

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

 

Element: scrollIntoView() method - Web APIs | MDN

The Element interface's scrollIntoView() method scrolls the element's ancestor containers such that the element on which scrollIntoView() is called is visible to the user.

developer.mozilla.org

 

옵션은 2가지인데, 

1. aligntotop :boolean

요소의 top 으로 이동할지 지정하는 옵션

 

2. scrollIntoViewOptions : Object

Object 에 Behavior, block, inline 옵션을 지정할 수 있다. 실험요소로 자세한 건 MDN 참고

'Front-End > Javascript' 카테고리의 다른 글

Web API : Intersection Observer API  (0) 2024.06.18

댓글