HTML onscroll 이벤트 속성은 HTML 문서에서 스크롤바를 사용하여 HTML 요소를 스크롤할 때 발생합니다.
구문
다음은 구문입니다 -
<tagname onscroll=”script”></tagname>
HTML onscroll 이벤트 Attribute −
의 예를 살펴보겠습니다.예시
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
padding: 20px;
}
.box-para {
border: 2px solid #fff;
padding: 10px;
width: 200px;
height: 200px;
overflow: scroll;
margin: 1rem auto;
}
</style>
</head>
<body>
<h1>HTML onscroll Event Attribute Demo</h1>
<p onscroll="scrollFn()" class="box-para">
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text. This is a paragraph element with some dummy text.
This is a paragraph element with some dummy text.</p>
<p>Scroll above paragraph text to increase its font size</p>
<script>
function scrollFn() {
document.querySelector(".box-para").style.fontSize = "1.5rem";
}
</script>
</body>
</html> 출력

onscroll 이벤트 속성이 작동하는 방식을 관찰하기 위해 단락 내용을 스크롤하십시오 -
