How to use JQuery .on() to catch the scroll event

前端 未结 3 375
既然无缘
既然无缘 2021-01-18 04:08

I\'m attempting to use the .on() from jQuery to catch a scroll event that is inside a tag.

so this was my solution:

  • the div id=\'popup\'
  • the
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 04:38

    The confusion is in how "on()" works. In jQuery when you say $(document).on(xx, "#popup", yy) you are trying to run yyy whenever the xx event reaches document but the original target was "#popup".

    If document is not getting the xx event, then that means it isn't bubbling up! The details are in the jQuery On documentation, but the three events "load", "error" and "scroll" do not bubble up the DOM.

    This means you need to attach the event directly to the element receiving it. $("#popup").on(xx,yy);

提交回复
热议问题