thesmart / jquery-scrollspy

A ScrollSpy library for detecting enter/exit of elements in the viewport when the user scrolls
Other
276 stars 99 forks source link

enable bubbling of the events `scrollSpy:enter` and `scrollSpy:exit` #10

Open Mithgol opened 10 years ago

Mithgol commented 10 years ago

Currently the events triggered by ScrollSpy do not bubble because they are triggered by the jQuery's .triggerHandler method which (according to the docs) is similar to .trigger() but one of the exceptions is the following:

Events triggered with .triggerHandler() do not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.

Unfortunately, for me it's an issue. Sometimes in my applications (PhiDo, for example) I have to initiate scrollspying on hundreds of elements. Installing a separate event handler on each of these elements (instead of only one handler on a parent element) seems superfluous.

Hence a pull request to replace .triggerHandler with a simple .trigger.

(Also fixes #8 because is based on its code branch.)