title: Why can't I reliably capture a mouseout event?
body: <p>I need to know when the mouse cursor leaves a <code>div</code>. So I hook up the <code>mouseout</code> event. However, if I move the mouse very quickly out of the <code>div</code>, the <code>mouseout</code> event <strong>doesn't fire</strong>. That's right: the mouse cursor <em>was</em> sitting still inside the <code>div</code>, it's now <em>outside</em> the <code>div</code>, and yet the <code>mouseout</code> callback hasn't been called. (It works fine if I don't move the mouse quite so fast.) </p>
  
  <p>This is true in the <strong>latest Google Chrome</strong> by the way – so not just an "old browsers" problem.</p>
  
  <p><strong>A workaround:</strong></p>
  
  <p>A question about this problem has been <a href="https://stackoverflow.com/questions/2597832/javascript-mouse-event-not-captured-properly-when-mouse-moved-very-fast">posed before</a>. Apparently it's just a fact of life, and the only workaround I've found is to manually monitor <code>mousemove</code> events, each time checking the cursor's x/y co-ordinates and seeing if they fall within the <code>div</code>’s bounding box, so you have more chances to "notice" if the cursor is no longer inside it. </p>
  
  <p>Compared to letting the browser do all this natively, performing calculations on every pixel move is a bit of a performance hit. It's also tedious to code.</p>
  
  <p><strong>On to my question...</strong></p>
  
  <p><em>Why</em> can't the browser can't reliably capture the <code>mouseout</code> event? If I can reliably tell when the mouse has left the <code>div</code> using the above workaround, why can't the browser do it?</p>
  
  <p>I understand (from the answer linked above) that JavaScript doesn't try to interpolate "frames". Say if you put a <code>mousemove</code> handler on the <code>document</code>, and quickly move the mouse 200 pixels to the right in a perfect horizontal line, you might <strong>not</strong> get 200 <code>mousemove</code> events. A few will be missed. I don't have a problem with that.</p>
  
  <p>But if some pixel movements are missed just as the mouse crosses the boundary of the <code>div</code>, why does it follow that the <code>mouseout</code> event should also be skipped? When the browser finally starts registering the mouse's position again (after a sudden fast movement), even if the mouse is now <em>miles</em> outside the box, the point is that it <em>used to be in the box and no longer is</em>. So why doesn't it then fire the mouseout event then? </p>
  
  <p>I just don't get why this would be a hard problem for the browser vendors to solve. (But I trust there might be a good reason, which I'm too stupid to think of.)</p>
  
  <p>I'm posting this question mainly out of curiosity, but I'm hoping the answer might give some insight that could help me work around the problem more efficiently. Also, any alternative workarounds (which are faster than the one presented above) would be welcome.</p>