-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
72 lines (54 loc) · 1.65 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
---
title: "Element: scrollTo() method"
short-title: scrollTo()
slug: Web/API/Element/scrollTo
page-type: web-api-instance-method
browser-compat: api.Element.scrollTo
---
{{APIRef}}
The **`scrollTo()`** method of the {{domxref("Element")}}
interface scrolls to a particular set of coordinates inside a given element.
## Syntax
```js-nolint
scrollTo(xCoord, yCoord)
scrollTo(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
element.scrollTo(0, 1000);
```
Using `options`:
```js
element.scrollTo({
top: 100,
left: 100,
behavior: "smooth",
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("Element.scrollTop")}}, {{domxref("Element.scrollLeft")}}
- {{domxref("Window.scrollTo()")}}