title: JavaScript MouseEvent.movementX and movementY large spikes
body: <p>After a pointer lock with Chrome, if you move the mouse, MouseEvent.movementX and MouseEvent.movementY will sometimes return a very large number that seems to be around half the size of the window.</p>
  
  <p>Here is a minimal code example:</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;canvas id="canvas" width="100" height="100" style="border: 1px solid"&gt;
          &lt;/canvas&gt;
          &lt;script&gt;
              var canvas = document.getElementById("canvas");
  
              canvas.addEventListener("mousedown", function() {
                  canvas.requestPointerLock();
              });
  
              document.addEventListener("mousemove", function() {
                  if(Math.abs(event.movementX) &gt; 100)
                      console.log(event.movementX);
              });
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My hunch is that when you call requestPointerLock() it doesn't actually lock the mouse in one position, but just hides it. When the mouse goes off the window then it snaps the mouse back to the center which causes a large spike in the variable.</p>
  
  <p>What is the cause of the large spike and how can I fix it?</p>