An event handler for scroll events on element
.
element.onscroll = functionReference
functionReference
is a reference to a function to be executed when element
is scrolled.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <style> #container { position: absolute; height: auto; top: 0; bottom: 0; width: auto; left: 0; right: 0; overflow: auto; } #foo { height:1000px; width:1000px; background-color: #777; display: block; } </style> </head> <body> <div id="container"> <div id="foo"></div> </div> <script type="text/javascript"> document.getElementById('container').onscroll = function() { console.log("scrolling"); }; </script> </body> </html>
The scroll
event is raised when the user scrolls the contents of an element. Element.onscroll
is equivalent to element.addEventListener("scroll" ... )
.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'onscroll' in that specification. | Living Standard | |
Document Object Model (DOM) Level 3 Events Specification The definition of 'onscroll' in that specification. | Obsolete | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | ? | ? | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onscroll