//detect when thing is in viewport from scrolling up or down, 50px from top

by Ian Roberts

HTML

<script src="//cdn.jsdelivr.net/jquery.waypoints/2.0.2/waypoints.min.js"></script>
<div class="thing"></div>
<div class="spacer"></div>
<div class="thing"></div>
<div class="spacer"></div>
<div class="thing"></div>
<div class="spacer"></div>
<div class="thing"></div>
<div class="spacer"></div>
<div class="thing"></div>
<div class="spacer"></div>

CSS

.thing {height:50px;background:#eaeaea;border:1px solid #ccc;}
.spacer {height:1000px;}

JavaScript

//detect when thing is in viewport from scrolling up or down, 50px from top
$.fn.waypoint.defaults = {
  context: window,
  continuous: true,
  enabled: true,
  horizontal: false,
  offset: 'bottom-in-view', //sets default waypoint
  triggerOnce: false
}

$('.thing').waypoint(function(down) {
  alert("thing in viewport has reached bottom");
});

$('.thing').waypoint(function(up) {
  alert("thing in viewport is 50px. from top");
}, { offset: 50 }); //overrides default waypoint to detect when item is at top of viewport

//waypoint documentation - http://imakewebthings.com/jquery-waypoints/#doc-waypoint