Window.scrollBy()
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
* Some parts of this feature may have varying levels of support.
Window.scrollBy() 메서드는 창에 있는 문서를 지정된 양만큼 스크롤합니다.
구문
js
scrollBy(x-coord, y-coord)
scrollBy(options)
매개변수
x-coord는 스크롤할 수평 픽셀 값입니다.y-coord는 스크롤할 수직 픽셀 값입니다.
- 혹은 -
반환 값
없음 (undefined).
예제
한 페이지 아래로 스크롤하려면.
js
window.scrollBy(0, window.innerHeight);
위로 스크롤하려면.
js
window.scrollBy(0, -window.innerHeight);
options 사용.
js
window.scrollBy({
top: 100,
left: 100,
behavior: "smooth",
});
참고
window.scroll()가 문서의 절대 위치로 스크롤하는데 반해, window.scrollBy()는 특정 양만큼 스크롤합니다.
window.scrollByLines()와 window.scrollByPages()를 참조하십시오.
명세서
| Specification |
|---|
| CSSOM View Module> # dom-window-scrollby> |