-
Notifications
You must be signed in to change notification settings - Fork 23.2k
Expand file tree
/
Copy pathindex.md
More file actions
69 lines (53 loc) · 1.61 KB
/
index.md
File metadata and controls
69 lines (53 loc) · 1.61 KB
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
---
title: "Element: scroll() method"
short-title: scroll()
slug: Web/API/Element/scroll
page-type: web-api-instance-method
browser-compat: api.Element.scroll
---
{{APIRef("CSSOM view API")}}
The **`scroll()`** method of the {{domxref("Element")}}
interface scrolls the element to a particular set of coordinates inside a given
element.
## Syntax
```js-nolint
scroll(xCoord, yCoord)
scroll(options)
```
### Parameters
- `xCoord`
- : The pixel along the horizontal axis of the element that you want displayed in the
upper left.
- `yCoord`
- : The pixel along the vertical axis of the element that you want displayed in the
upper left.
- `options`
- : An object containing the following properties:
- `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
```js
// Put the 1000th vertical pixel at the top of the element
element.scroll(0, 1000);
```
Using `options`:
```js
element.scroll({
top: 100,
left: 100,
behavior: "smooth",
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}