쓸만한 주저리

div, textarea에서 button 눌러서 scroll 조종

봄돌73 2009. 5. 22. 11:54
<script>
  function objscroll(id,amount){
    var obj=document.getElementById(id)
    obj.scrollTop=obj.scrollTop+amount
  }
</script>
<div>
  <div id=d style=width:200px;height:300px;overflow:auto>
    <div style=width:180px;height:1000px;background:blue></div>
  </div>
  <input type=button value=up onclick=objscroll('d',-10)>
  <input type=button value=down onclick=objscroll('d',10)>
</div>

<div>
  <div>
    <textarea id=t style=width:200px;height:300px;overflow:auto>
fdgsd
fgs
dfg
sdfg
s
dfg
sdfg
sd
fgs
dfg
sdf
gs
dfg
sdf
gsd
fg
dsg
sdf
gs
dfg
sd
fgs
dfg
dfg
sdf
gs
dfg
sdf
gsd
fg
dsfg
sdfg
sdf
d
    </textarea>
  </div>
  <input type=button value=up onclick=objscroll('t',-10)>
  <input type=button value=down onclick=objscroll('t',10)>
</div>