x-coord is the horizontal coordinate and
y-coord is the vertical coordinate. The values are measured in pixels, and you can use negative values to scroll up and to the left.
Here’s an example that scrolls the window to the top left corner:
You can also use the
scrollBy method to scroll by a certain amount of pixels, rather than to a specific coordinate:
For example, the following code will scroll the window down by 100 pixels:
Note that these methods affect the scroll position of the entire window, not just a specific element. If you want to scroll an element within the page, you can use the
scrollLeft properties. For example:
document.getElementById("element-id").scrollTop = 100;
This will set the scroll position of the element with the ID “element-id” to 100 pixels from the top.