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

白昼怎懂夜的黑 提交于 2019-12-18 12:46:13

问题


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!!!!!


回答1:


Try using window:

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



回答2:


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.



来源:https://stackoverflow.com/questions/7534277/document-scroll-is-not-firing-in-ie8-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!