-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
66 lines (48 loc) · 1.27 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
---
title: "Element: scrollBy() method"
short-title: scrollBy()
slug: Web/API/Element/scrollBy
page-type: web-api-instance-method
browser-compat: api.Element.scrollBy
---
{{APIRef}}
The **`scrollBy()`** method of the {{domxref("Element")}}
interface scrolls an element by the given amount.
## Syntax
```js-nolint
scrollBy(x-coord, y-coord)
scrollBy(options)
```
### Parameters
- `x-coord` is the horizontal pixel value that you want to
scroll by.
- `y-coord` is the vertical pixel value that you want to scroll
by.
\- 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`
- : Specifies whether the scrolling should animate smoothly (`smooth`), happen instantly in a single jump (`instant`), or let the browser choose (`auto`, default).
### Return value
None ({{jsxref("undefined")}}).
## Examples
```js
// scroll an element
element.scrollBy(300, 300);
```
Using `options`:
```js
element.scrollBy({
top: 100,
left: 100,
behavior: "smooth",
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}