onscroll event
Example
Execute JavaScript when an element is scrolled.
<div onscroll="myFunction()">Try it »
Definition and Usage
The onscroll event is triggered when the scrollbar of an element is scrolling.
Tip: Use CSS overflow style attribute to create a scrollbar for the element.
Browser support
| Event | |||||
|---|---|---|---|---|---|
| onscroll | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
<
element
onscroll="
myScript
">Try it
In JavaScript:
object
.onscroll=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("scroll",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
Technical Details
| Does it support bubbling: | Yes |
|---|---|
| Is it cancelable: | No |
| Event type: | Event |
| Supported HTML tags: |
,
, , |
Event Object