GlobalEventHandlers.onscroll
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.
Un manejador de eventos para desplazamiento en element
.
Sintaxis
js
element.onscroll = functionReference;
Parámetros
functionReference
es una referencia a una función para ser ejecutada cuando element
es desplazado (enrollado).
Example
html
<!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>
Notas
El evento es generado cuando el usuario realiza desplazamiento (scrolls) sobre el contenido de un elemento. Element.onscroll
es equivalente a element.addEventListener("scroll" ... )
.
Especificaciones
Specification |
---|
CSSOM View Module # eventdef-document-scroll |
HTML # handler-onscroll |
Compatibilidad con navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scroll event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.