/
index.md
85 lines (61 loc) · 2.05 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "Window: scroll() method"
short-title: scroll()
slug: Web/API/Window/scroll
page-type: web-api-instance-method
browser-compat: api.Window.scroll
---
{{APIRef}}
The **`Window.scroll()`** method scrolls the window to a
particular place in the document.
## Syntax
```js-nolint
scroll(x-coord, y-coord)
scroll(options)
```
### Parameters
- `x-coord` is the pixel along the horizontal axis of the document that you
want displayed in the upper left.
- `y-coord` is the pixel along the vertical axis of the document that you
want displayed in the upper left.
\- or -
- `options`
- : A dictionary containing the following parameters:
- `top`
- : Specifies the number of pixels along the Y axis to scroll the window or element.
- `left`
- : Specifies the number of pixels along the X axis to scroll the window or element.
- `behavior`
- : Determines whether scrolling is instant or animates smoothly. This option is a string which must take one of the following values:
- `smooth`: scrolling should animate smoothly
- `instant`: scrolling should happen instantly in a single jump
- `auto`: scroll behavior is determined by the computed value of {{cssxref("scroll-behavior")}}
### Return value
None ({{jsxref("undefined")}}).
## Examples
```html
<!-- put the 100th vertical pixel at the top of the window -->
<button onclick="scroll(0, 100);">click to scroll to the 100th pixel</button>
```
Using `options`:
```js
window.scroll({
top: 100,
left: 100,
behavior: "smooth",
});
```
## Notes
{{domxref("Window.scrollTo()")}} is effectively the same as this method. For relative
scrolling, see {{domxref("Window.scrollBy()")}}, {{domxref("Window.scrollByLines()")}},
and {{domxref("Window.scrollByPages()")}}.
For scrolling elements, see {{domxref("Element.scrollTop")}} and
{{domxref("Element.scrollLeft")}}.
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Window.scrollByLines()")}}
- {{domxref("Window.scrollByPages()")}}
- {{domxref("Element.scrollIntoView()")}}