scrollTop 예제 - 스크롤 수직위치 반환 scrollTop 정의 scrollTop 구문
<style> #box { height: 250px; width: 250px; overflow: auto; } #content { height: 1000px; width:750px ; background-color: tomato; } </style> <div id="box" onscroll="homzzang()"> <div id="content">홈짱닷컴 Homzzang.com</div> </div> <p id="demo"></p> <script> function homzzang() { var box = document.getElementById("box"); var x = box.scrollLeft; var y = box.scrollTop; var n = "수평: " + x + "px<br>수직: " + y + "px"; document.getElementById ("demo").innerHTML = n; } </script> 결과보기
<style>
#box {
height: 250px;
width: 250px;
overflow: auto;
}
#content {
height: 1000px;
width:750px ;
background-color: tomato;
</style>
<div id="box" onscroll="homzzang()">
<div id="content">홈짱닷컴 Homzzang.com</div>
</div>
<p id="demo"></p>
<script>
function homzzang() {
var box = document.getElementById("box");
var x = box.scrollLeft;
var y = box.scrollTop;
var n = "수평: " + x + "px<br>수직: " + y + "px";
document.getElementById ("demo").innerHTML = n;
</script>
결과보기
요소의 내용이 세로로 스크롤되는 픽셀 수 설정/반환.
반환 element.scrollTop 설정 element.scrollTop = pixels
반환
element.scrollTop
설정
element.scrollTop = pixels