Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="div-a" class="q a"></div>
  <div id="div-b" class="q b"></div>
  <div id="div-c" class="q c"></div>
  <div id="div-d" class="q d"></div>
  
</body>
</html>
 
html, body { margin: 0; padding: 0; }
.q { height: 100vh }
.a { background: blue }
.b { background: red }
.c { background: yellow }
.d { background: green }
 
var vh = window.innerHeight;
var divs = document.querySelectorAll('.q');
window.addEventListener('scroll', function() {
  var scrolledY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
  var divIdx = Math.floor(scrolledY / vh);
  console.log('scrolled to: ' + divs[divIdx].id);
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers