garand / sticky

jQuery Plugin for Sticky Objects
Other
3.3k stars 1.06k forks source link

allows dev to attach scroll listener to specific element #280

Closed Pixelik closed 6 years ago

Pixelik commented 6 years ago

The plugin is currently attaching one single scroll listener to the window

In some HTML layouts there are only specific elements that are scrollable and in those cases $(window).on('scroll', handler) has no effect, the handler is never called.

This PR will allow a dev to define which element to attach the scroll listener to :

$(element).sticky({
  ....
  ...
  scroller: document.getElementById('my-scroller')
});

If no scroller is defined then window will be used instead.