Scrolling on web pages

Prev Next

In order to implement a scrolling action on a web page, JavaScript can be used.

Add an instruction: Execute code

In the code window, add the following:

window.scrollBy(0,100);

window → refers to the browser’s window (the whole page).

scrollBy(x, y) → scrolls the document by a relative offset, not to an absolute position.

The first argument (x) = horizontal scroll in pixels.

The second argument (y) = vertical scroll in pixels.

So in this case:

0 → no horizontal movement.

100 → move the page down by 100 pixels from the current position.

Changing the value of 100 to something higher, like 500 for example, will increase the scroll amount so it scrolls further down, in this case 500 pixels.