-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrollby markdown #6138
base: main
Are you sure you want to change the base?
Scrollby markdown #6138
Conversation
…ginally stated that method works with one or no parameters -- this is false. Mixed up two different methods in my head). General housekeeping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @phillip-alter, thank you for contributing to Codecademy Docs, the entry is nicely written! 😄
I've suggested a few changes, could you please review and modify those at your earliest convenience? Thank you! 😃
Title: 'scrollBy()' | ||
Description: 'Scrolls the window's content by a specified number of pixels, relative to the current scroll position.' | ||
Subjects: | ||
- 'Web Development' | ||
- 'Computer Science' | ||
Tags: | ||
- 'Functions' | ||
- 'Parameters' | ||
- 'Arguments' | ||
CatalogContent: | ||
- 'introduction-to-javascript' | ||
- 'paths/front-end-engineer-career-path' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title: 'scrollBy()' | |
Description: 'Scrolls the window's content by a specified number of pixels, relative to the current scroll position.' | |
Subjects: | |
- 'Web Development' | |
- 'Computer Science' | |
Tags: | |
- 'Functions' | |
- 'Parameters' | |
- 'Arguments' | |
CatalogContent: | |
- 'introduction-to-javascript' | |
- 'paths/front-end-engineer-career-path' | |
Title: 'scrollBy()' | |
Description: 'Scrolls the window content by a specified number of pixels, relative to the current scroll position' | |
Subjects: | |
- 'Computer Science' | |
- 'Web Development' | |
Tags: | |
- 'Arguments' | |
- 'Functions' | |
- 'Parameters' | |
CatalogContent: | |
- 'introduction-to-javascript' | |
- 'paths/front-end-engineer-career-path' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags and subjects should be in alphabetical order.
Avoid apostrophe in description
- 'paths/front-end-engineer-career-path' | ||
--- | ||
|
||
The **`scrollBy()`** method is a function provided by the browser's window object. The method will scroll the user's window down, right, left, or up, depending on the parameters input into the method. The scrolling occurs relative to the current scroll position, meaning that if the user has already scrolled 100 pixels down a page, using `scrollBy()` to scroll a further 100 pixels down will cause the user to be 200 pixels down the page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The **`scrollBy()`** method is a function provided by the browser's window object. The method will scroll the user's window down, right, left, or up, depending on the parameters input into the method. The scrolling occurs relative to the current scroll position, meaning that if the user has already scrolled 100 pixels down a page, using `scrollBy()` to scroll a further 100 pixels down will cause the user to be 200 pixels down the page. | |
The **`scrollBy()`** method is a function provided by the browser's [window](https://www.codecademy.com/resources/docs/javascript/window) object. It scrolls the window content up, down, left, or right based on the specified parameters. The scrolling occurs relative to the current scroll position, meaning if the user has already scrolled 100 pixels down and `scrollBy(0, 100)` is called, the new scroll position will be 200 pixels down the page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added link for window object, reframed a bit
`scrollBy()` receives up to two parameters. The first is a number, which represents the number of pixels the user desires to scroll horizontally, for the x-coordinate. The second is a number, which represents the number of pixels the user desires to scroll vertically, for the y-coordinate. | ||
|
||
These numbers can be **positive** or **negative**. Positive numbers in the x-coordinate parameter will scroll right, and positive numbers in the y-coordinate parameter will scroll down. Negative numbers in the x-coordinate parameter will scroll left, and negative numbers in the y-coordinate parameter will scroll up. | ||
|
||
Below are some examples of how `scrollBy()` is composed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these need to be added below the syntax as:
x-coordinate
:y-coordinate
:
Putting them in bullets would make the doc more readable
|
||
window.scrollBy(x-coordinate,y-coordinate); | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, you can also add the alternative syntax as:
Alternatively, there is another syntax as follows:
scrollBy(options)
options
:
|
||
## Example 1 | ||
|
||
The following example uses the `scrollBy()` function to scroll a window down when a button is pressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following example uses the `scrollBy()` function to scroll a window down when a button is pressed. | |
The following example uses the `scrollBy()` function to scroll the window down by _200_ pixels when a button is clicked: |
// Creating a reference to a scroll button on an external HTML document. | ||
const scrollButton = document.getElementById("scrollButton"); | ||
|
||
// When the button is pressed, the window scrolls down by 200 pixels. | ||
scrollButton.addEventListener("click", function() { | ||
window.scrollBy(0,200); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Creating a reference to a scroll button on an external HTML document. | |
const scrollButton = document.getElementById("scrollButton"); | |
// When the button is pressed, the window scrolls down by 200 pixels. | |
scrollButton.addEventListener("click", function() { | |
window.scrollBy(0,200); | |
}); | |
// Get a reference to the button element. | |
const scrollButton = document.getElementById("scrollButton"); | |
// Scroll down by 200 pixels when the button is clicked. | |
scrollButton.addEventListener("click", function() { | |
window.scrollBy(0, 200); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reframed comments
``` | ||
## Example 2 | ||
|
||
The following example uses the `scrollBy()` function to scroll a window to the left and up 100 pixels each. This syntax demonstrates using `scrollBy()` with negative numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following example uses the `scrollBy()` function to scroll a window to the left and up 100 pixels each. This syntax demonstrates using `scrollBy()` with negative numbers. | |
The following example scrolls the window _100_ pixels to the left and _100_ pixels up using negative values: |
// Creating a reference to a scroll button on an external HTML document. | ||
const scrollButton2 = document.getElementById("scrollButton2"); | ||
|
||
// When the button is pressed, the window scrolls left by 100 pixels and up by 100 pixels. | ||
scrollButton2.addEventListener("click", function() { | ||
window.scrollBy(-100,-100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Creating a reference to a scroll button on an external HTML document. | |
const scrollButton2 = document.getElementById("scrollButton2"); | |
// When the button is pressed, the window scrolls left by 100 pixels and up by 100 pixels. | |
scrollButton2.addEventListener("click", function() { | |
window.scrollBy(-100,-100); | |
// Get a reference to the second button element. | |
const scrollButton2 = document.getElementById("scrollButton2"); | |
// Scroll left by 100 pixels and up by 100 pixels when the button is clicked. | |
scrollButton2.addEventListener("click", function() { | |
window.scrollBy(-100, -100); | |
}); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reframed comments and fixed code indentation (it should be 2 spaces only)
I made the requested changes to the document. Please re-review and let me know if any further changes are required. Thank you! |
Description
Created scrollBy() page. Defined scrollBy() and provided in-code examples.
Issue Solved
Closes #6105
Type of Change
Checklist
main
branch.Issues Solved
section.