Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  
  <h2>Scroll the box, then Press the Button</h2>
  <div class="box">
    <div class="scroller">
    </div>
  </div>
  
  <output></output>
  
  <button>Get ScrollLeft and ScrollTop</button>
</body>
</html>
 
body {
  font-family: Arial, sans-serif;
  padding-top: 10px;
  text-align: center;
}
.box {
  width: 300px;
  height: 300px;
  overflow: auto;
  background: #ccc;
  margin: 0 auto 40px auto;
}
.scroller {
  width: 900px;
  height: 1200px;
}
button {
  display: block;
  width: 220px;
  margin: 50px auto;
}
output {
  text-align: center;
  display: block;
  min-height: 50px;
  line-height: 25px;
}
 
var box = document.querySelector('.box'),
    op = document.querySelector('output'),
    btn = document.querySelector('button');
btn.addEventListener('click', function () {
  op.innerHTML = 'ScrollTop is: ' + box.scrollTop + '<br>' + 'ScrollLeft is: ' + box.scrollLeft;
}, false);
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ImpressiveWebspro
0viewers