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

前端 未结 3 369
既然无缘
既然无缘 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:43

    The event is simply scroll, not scroll#popup.

    // http://ejohn.org/blog/learning-from-twitter
    // Also, be consistent with " vs '
    var $fixedHeader = $('.fixedHeader').css('position', 'relative');
    
    $(document).on('scroll', '#popup', function() {
       console.log('scrolling'); // you *really* don't want to alert in a scroll
       $fixedHeader.css("top", getScrollTop()); 
    });
    

提交回复
热议问题