Sự kiện onscroll xảy ra khi thanh cuộn của phần tử được cuộn.
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
div { border: 2px solid blue; width: 300px; height: 100px; overflow: scroll; }
</style>
</head>
<body>
<div id="content">
Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo.
Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo.
Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo.
Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo.
Đây là văn bản demo. Đây là văn bản demo. Đây là văn bản demo.
</div>
<p id="myScroll"></p>
<script>
document.getElementById("content").onscroll = function() { myFunction() };
function myFunction() {
document.getElementById("myScroll").innerHTML = "Đã cuộn thành công!";
}
</script>
</body>
</html>