창 scrollBy()
예시
문서를 가로로 100px 스크롤:
window.scrollBy(100, 0);
문서를 세로로 100px 스크롤합니다.
window.scrollBy(0, 100);
아래에 더 많은 예가 있습니다.
정의 및 사용
메서드 는 scrollBy()
지정된 픽셀 수만큼 문서를 스크롤합니다.
통사론
window.scrollBy(x, y)
또는 그냥:
scrollBy(x, y)
매개변수
Parameter | Description |
x | Required. Number of pixels to scroll (horizontally). Positive values scroll to the right, negative values to the left. |
y | Required. Number ofpixels to scroll (vertically). Positive values scroll down, negative values scroll up. |
반환 값
없음 |
더 많은 예
문서를 위아래로 스크롤합니다.
<button onclick="scrollWin(0, 50)">Scroll down</button>
<button onclick="scrollWin(0, -50)">Scroll up</button>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
문서를 좌우로 스크롤:
<button onclick="scrollWin(100, 0)">Scroll right</button>
<button onclick="scrollWin(-100, 0)">Scroll left</button>
<script>
function scrollWin(x, y) {
window.scrollBy(x, y);
}
</script>
브라우저 지원
scrollBy()
모든 브라우저에서 지원됩니다:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |