Khi một phần tử được cuộn, thuộc tính onscroll kích hoạt. Bạn có thể chạy mã sau để triển khai thuộc tính onscroll:
Ví dụ
<!DOCTYPE html>
<html>
<head>
<style>
#myid {
width: 250px;
height: 80px;
border: 2px solid blue;
overflow: scroll;
}
</style>
</head>
<body>
<p>Cuộn hộp bên dưới.</p>
<div id="myid" onscroll="display()">Đâ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. <br><br></div>
<script>
function display() {
document.getElementById("myid").style.color = "blue";
}
</script>
</body>
</html>