//detect when thing is in viewport, scrolling up or down, at top or bottom
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, scrolling up or down, at top or bottom
$.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 has reached top");
}, { offset: 0 }); //overrides default waypoint to detect when item is at top of viewport
//waypoint documentation - http://imakewebthings.com/jquery-waypoints/#doc-waypoint