-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
54 lines (35 loc) · 1.15 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: window.scrollTo
slug: Web/API/Window/scrollTo
---
{{APIRef}}
**`Window.scrollTo()`** は文書内の特定の組み合わせの座標までスクロールします。
## 構文
```
window.scrollTo(x-coord, y-coord)
window.scrollTo(options)
```
### 引数
- `x-coord` は、左上に表示されたい文書の水平軸上のピクセルです。
- `y-coord` は、左上に表示されたい文書の垂直軸上のピクセルです。
\- または -
- `options` は {{domxref("ScrollToOptions")}} 辞書です。
## 例
```js
window.scrollTo(0, 1000);
```
`options` の使用例:
```js
window.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});
```
## 注
{{domxref("Window.scroll()")}} はこのメソッドとほぼ同じです。相対スクロールについては、 {{domxref("Window.scrollBy()")}}, {{domxref("Window.scrollByLines()")}}, {{domxref("Window.scrollByPages()")}} を参照してください。
要素をスクロールするには、 {{domxref("Element.scrollTop")}} および {{domxref("Element.scrollLeft")}} を参照してください。
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}