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>
  <h1>View timeline current time</h1>
  <p>Scroll down to see subject</p>
  <div id="log"></div>
  <div id="target">Subject</div>
</body>
</html>
 
body {
  height: 400vh;
  overflow-x: hidden;
}
#log {
  position: fixed;
  top: 10px;
  left: 10px;
  background: white;
  border: 1px solid #aaa;
}
@keyframes anim {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}
#target {
  position: absolute;
  top: 150vh;
  width: 100%;
  height: 50vh;
  background: #afa;
  animation: anim;
  animation-timeline: view();
}
 
function update() {
  let target = document.getElementById('target');
  let anim = target.getAnimations()[0];
  document.getElementById('log').innerHTML =
      `Time: ${anim.timeline.currentTime}`
}
window.addEventListener('scroll', update);
requestAnimationFrame(update);
Output

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

Dismiss x
public
Bin info
flackrpro
0viewers