Languages
[Edit]
EN

JavaScript - onscroll event example

3 points
Created by:
ArcadeParade
666

In this article, we would like to show you how to use onscroll event in JavaScript.

Quick solution:

or:

or:

Note: it is very important to work on element that has scrollable content to handle onscroll event.

 

Practical examples

Edit

There are three common ways how to use onscroll event:

  • with event listener,
  • with element attribute,
  • with element property.

To enable content scrolling, example elements to have assigned height and overflow styles.

1. Event listener based example

Edit

In this section, we want to show how to use scroll event on div element via event listener mechanism.

2. Attribute based example

Edit

In this section we want to show how to use onscroll event on div element via attribute.

3. Property based example

Edit

In this section, we want to show how use onscroll event on div element via property.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - events

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join