title: jQuery: Fire mousemove events less often
body: <p>I'm trying to figure out a clean way to aggregate mousemove events so that I ensure my code gets called, but only once every 250-300 milliseconds.</p>
  
  <p>I've thought about using something like the following, but was wondering if there was a better pattern, or something jQuery provides that will do the same thing:</p>
  
  <pre><code>var mousemove_timeout = null;
  
  $('body').mousemove(function() {
    if (mousemove_timeout == null) {
      mousemove_timeout = window.setTimeout(myFunction, 250);
    }
  });
  
  function myFunction() {
    /*
     * Run my code...
     */
  
    mousemove_timeout = null;
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> The accepted answer below would work perfectly for this situation, however, I found that the <code>mousestop()</code> functionality provided in the answer actually eliminated my need for the aggregation, so if you're reading this question and looking for an answer, see if the <a href="http://www.richardscarrott.co.uk/posts/view/jquery-mousestop-event">mousestop</a> plugin is what you really need!</p>