$(document).scroll is not firing in IE8 only

2019-02-05 14:33发布

I have a site running some javascript. In IE8 only, the $(document).scroll is not firing when you scroll with or without the mousewheel. Code snippet below:

$(document).scroll(function () {
        //do something on scroll
      });

Is there a specific reason this function won't fire in IE8? I have searched online with no success.

Thanks for all advice and tips in advance!!!!!

2条回答
我命由我不由天
2楼-- · 2019-02-05 15:16

Try using window:

  $(window).scroll(function () {
    //do something on scroll
  });
查看更多
做自己的国王
3楼-- · 2019-02-05 15:28

For a lot of areas, IE ties the event to window rather than document as other browsers will. $(window).scroll(function(e) {}); is what you're after here. Should generally also work in most other browsers too, but if not, use a check on the navigator to find IE and use window or document based on that Boolean.

查看更多
登录 后发表回答