title: JQuery / Javascript - Mouse Location completely off
body: <p>I'm trying to make a 'draw' app, which allows the user to draw something by dragging their mouse over a canvas.</p>
  
  <p>I want to draw a 'pixel' where the user drags their mouse, however: The location of the mouse and the location where the 'pixels' get drawn are not the same.
  I've searched all over the internet but I don't know what the difference is with my version and with theirs. </p>
  
  <p>Image: <a href="https://i.stack.imgur.com/UXWEJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UXWEJ.png" alt="enter image description here"></a></p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Drawer&lt;/title&gt;
      &lt;script src="jquery-2.2.1.min.js"&gt;&lt;/script&gt;
      &lt;script src="scripting/draw.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;canvas id="drawGround" style="width: 500px; height: 500px; margin: 0 auto; border: 1px solid black;"&gt;&lt;/canvas&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
    var drawSize = 3;
    var canDrawCanvas = false;
    const canvasID = "#drawGround";
  
    document.onmouseup = function() {
      canDrawCanvas = false;
    };
  
    $(canvasID).mousedown(function() {
      canDrawCanvas = true;
    });
    $(canvasID).mousemove(function(event) {
      if (canDrawCanvas) handleDrawing(event);
  
    });
  
    function handleDrawing(mouseEvent) {
      var canvas = document.getElementById(canvasID.substring(1));
      var context = canvas.getContext('2d');
      context.fillRect(mouseEvent.pageX, mouseEvent.pageY, drawSize, drawSize);
    }
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;canvas id="drawGround" style="width: 500px; height: 500px; margin: 0 auto; border: 1px solid black;"&gt;&lt;/canvas&gt;</code></pre>
  </div>
  </div>
  </p>