scrollLeft 예제
<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>
결과보기
새로 고침 가로 스크롤바 오른쪽 위치
document.body.scrollLeft =10000;
균이 님 https://sir.kr/qa/312442