title: Run Jquery function on window events: load, resize, and scroll?
body: <p>How do I run a jquery function on window events: load, resize, and scroll?</p>
  
  <p>Here is my code
  I'm trying to detect if a div is viewable and then if it is run some ajax code...</p>
  
  <hr>
  
  <pre><code>&lt;script&gt;
  function topInViewport(element) {
      return $(element).offset().top &gt;= $(window).scrollTop() &amp;&amp; $(element).offset().top          &lt;= $(window).scrollTop() + $(window).height();
   }
  
   &lt;/script&gt;
  
  &lt;script&gt;
  topInViewport($("#mydivname"))
  {
  // ajax code goes here
  }
  </code></pre>