HTML DOM scrollIntoView 메서드
예시
id="content"인 요소를 브라우저 창의 보이는 영역으로 스크롤합니다.
var elmnt = document.getElementById("content");
elmnt.scrollIntoView();
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
scrollIntoView() 메서드는 지정된 요소를 브라우저 창의 보이는 영역으로 스크롤합니다.
브라우저 지원
표의 숫자는 이 방법을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.
Method | |||||
---|---|---|---|---|---|
scrollIntoView | 28.0 | 8.0 | 1.7 | 5.0 | 38.0 |
통사론
element.scrollIntoView(alignTo)
매개변수
Parameter | Type | Description |
---|---|---|
alignTo | Boolean | Optional. A boolean value that indicates the type of the align:
true - the top of the element will be aligned to the top of the visible area of the scrollable ancestor false - the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor. If omitted, it will scroll to the top of the element. Note: Depending on the layout of other elements, some elements may not be scrolled completely to the top or to the bottom. |
기술적 세부 사항
반환 값: | 반환 값 없음 |
---|---|
DOM 버전 | 실험적 |
더 많은 예
예시
요소의 맨 위 또는 맨 아래로 스크롤합니다.
var elmnt = document.getElementById("content");
function scrollToTop()
{
elmnt.scrollIntoView(true); // Top
}
function scrollToBottom() {
elmnt.scrollIntoView(false); // Bottom
}