forked from Codecademy/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Term Entry] Javascript Window function: scroll() Codecademy#6106
- Loading branch information
1 parent
e5c446f
commit e582eea
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
Title: 'scroll()' | ||
Description: 'Scrolls the document to a specific position on the page.' | ||
Subjects: | ||
- 'Web Development' | ||
- 'Computer Science' | ||
Tags: | ||
- 'Window' | ||
- 'Scrolling' | ||
- 'Functions' | ||
CatalogContent: | ||
- 'introduction-to-javascript' | ||
- 'paths/front-end-engineer-career-path' | ||
--- | ||
|
||
**`scroll()`** is a method of the global `window` object that allows users to programmatically scroll the document to a specified position. | ||
|
||
## Syntax | ||
|
||
The `scroll()` method accepts either two numerical parameters (`x` and `y` coordinates) or an object with specific properties that control scrolling behavior. | ||
## Syntax | ||
|
||
The `scroll()` method accepts either two numerical parameters (`x` and `y` coordinates) or an object with specific properties that control scrolling behavior. | ||
|
||
```pseudo | ||
window.scroll(x, y) | ||
window.scroll(options) | ||
``` | ||
|
||
## Example 1 | ||
The following example scrolls the page to the top-left corner: | ||
|
||
window.scroll(0, 0); | ||
|
||
|
||
## Example 2 | ||
The following example scrolls smoothly to 500 pixels down the page: | ||
|
||
window.scroll({ | ||
top: 500, | ||
left: 0, | ||
behavior: "smooth" | ||
}); | ||
|
||
|
||
## Codebyte Example | ||
In the following example, the scroll() method moves the page down by 300 pixels: | ||
|
||
console.log('Scrolling down...'); | ||
setTimeout(() => { | ||
window.scroll({ | ||
top: 300, | ||
behavior: 'smooth' | ||
}); | ||
}, 2000); |