How to capture all scrolling events on a page without attaching an onscroll handler to every single container

后端 未结 4 786
青春惊慌失措
青春惊慌失措 2020-12-28 12:57

Consider the following Web page:

 
   
     
4条回答
  •  太阳男子
    2020-12-28 13:26

    The simplest way to detect all scroll events in modern browser would be using 'capturing' rather than 'bubbling' when attaching the event:

    window.addEventListener('scroll', function(){ code goes here }, true)
    

    Unfortunately as I am aware there is no equivalent in older browser such as <= IE8

提交回复
热议问题