scrollIntoView() 예제
<style> #box { height: 250px; width: 250px; overflow: auto; background: yellow; } #content { margin:500px; height: 500px; width: 500px; background-color: tomato; } </style> <button onclick="homzzang()">클릭</button> <div id="box"> <div id="content"> 홈짱닷컴 Homzzang.com </div> </div> <script> function homzzang() { var content = document.getElementById("content"); content.scrollIntoView(); } </script> 결과보기
<style>
#box {
height: 250px;
width: 250px;
overflow: auto;
background: yellow;
}
#content {
margin:500px;
height: 500px;
width: 500px;
background-color: tomato;
</style>
<button onclick="homzzang()">클릭</button>
<div id="box">
<div id="content">
홈짱닷컴 Homzzang.com
</div>
<script>
function homzzang() {
var content = document.getElementById("content");
content.scrollIntoView();
</script>
결과보기