HTML onscroll Event Attribute
Example
Execute a JavaScript when a <div> element is being scrolled:
<div onscroll="myFunction()">
Try it Yourself »
Definition and Usage
The onscroll attribute fires when an element's scrollbar is being scrolled.
Tip: use the CSS overflow style property to create a scrollbar for an element.
Browser Support
Event Attribute | |||||
---|---|---|---|---|---|
onscroll | Yes | Yes | Yes | Yes | Yes |
Differences Between HTML 4.01 and HTML5
The onscroll attribute is new in HTML5.
Syntax
<element onscroll="script">
Attribute Values
Value | Description |
---|---|
script | The script to be run on onscroll |
Technical Details
Supported HTML tags: | <address>, <blockquote>, <body>, <caption>, <center>, <dd>, <dir>, <div>, <dl>, <dt>, <fieldset>, <form>, <h1> to <h6>, <html>, <li>, <menu>, <object>, <ol>, <p>, <pre>, <select>, <tbody>, <textarea>, <tfoot>, <thead>, <ul> |
---|
Related Pages
HTML DOM reference: onscroll event
❮ HTML Event Attributes