title: Faster alternative to $(window).scroll?
body: <p>I've noticed that the jQuery scroll bind of $(window).scroll tends to lag down pages a significant amount. For example, I have elements on my page change styles when I scroll past them using the following script:</p>
  
  <pre><code>$(window).scroll(function() {
       var bottom_of_window = $(window).scrollTop() + $(window).height();
       $('.ElementsToBeChanged').each(function() { 
              var bottom_of_object = $(this).offset().top + $(this).outerHeight();
              if (bottom_of_window &gt; bottom_of_object) {
                  //Add my styles
              }
          });
  
  });
  </code></pre>
  
  <p>It understandably makes the website laggy, since it constantly runs on scroll, but I haven't come across any alternative for triggering events when objects are scrolled past. These kinds of websites that trigger events on scroll seem pretty common; What do they use to bypass this lag?</p>