imakewebthings/jquery-waypoints — Issue #32: Recalculating offset when using sticky and infinite scrolling together
Author: ninjabiscuit
Created: 2011-12-13 18:36:10+00:00
State: open

I tried using sticky waypoints and infinite scrolling waypoints together on a recent site. The skicky element was a notification and follows the user as they scroll down the page. When the user reaches the bottom of the page, more articles are insterted into the dom and scrolling can continue. However, as new articles were loaded in, a refresh would be triggered and the offset for the sticky would be recalculated. This results in the sticky, no longer being sticky :(

I managed to fix this temporarily by setting a sticky option when the waypoint is initialised, setting the value to el.offset().top. I then edited line 413 of waypoints and put a conditional in so that if there sticky is set o.offset, refers to that:

o.offset = (o.options.sticky) ? o.options.sticky : o.element.offset().top - contextOffset + contextScroll - adjustment;

Am I missing something in how waypoints should be set up?

I haven't got time to sort this issue out more elegantly and possibly I don't even really understand the problem properly, but when I do have more time I'll try for a better solution and turn it into a pull request