Javascript examples for DOM Event:addEventListener
The onscroll event occurs when an element's scrollbar is being scrolled.
Bubbles | No |
---|---|
Cancelable | No |
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> |
<!DOCTYPE html> <html> <head> <style> div {// ww w. j ava2 s. co m border: 1px solid black; width: 200px; height: 100px; overflow: scroll; } </style> </head> <body> <p>Try the scrollbar in the div</p> <div id="myDIV"> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <br><br> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <br><br> </div> <p id="demo"></p> <script> document.getElementById("myDIV").addEventListener("scroll", myFunction); function myFunction() { document.getElementById("demo").innerHTML = "You scrolled in div."; } </script> </body> </html>