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

前端 未结 3 371
既然无缘
既然无缘 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条回答
  •  别那么骄傲
    2021-01-18 04:42

    As @Venar303 says, scroll doesn't bubble, thus binding to document will not work.

    Use this:

    $('#popup').on('scroll', function() {});
    

    Instead of this:

    $(document).on('scroll', '#popup', function() {});
    

提交回复
热议问题