context option
Default
window
Possible Values
Any element that is an ancestor of the waypoint element.
The context
option defines which scrollable element the waypoint acts within. This is perhaps easiest to explain by example, so let's look at one. Here we have the following HTML, CSS, and JavaScript:
This results in…
As you can see, this waypoint handler is triggered when the top of the element hits the top of its context element. The default of window
covers the most common case, the user is scrolling the window and we want to react to an element's position in relation to the top of the window.
The other part of this equation, where the waypoint triggers, can be controlled with the offset option. As with the default of window
, this offset is calculated in relation to the context. For example, an offset of '50%'
will trigger when the top of the element hits the midpoint in the context's height.
If you're using the jQuery or Zepto builds of Waypoints, you can pass a CSS selector string as the context
option, instead of an HTMLElement, and Waypoints will call closest to find the context element.