Mouse event[X and Y coordinates]












0















I'm new to electron and somehow my JS script is not working in electron.
Here is my Javascript .I would like to implement this code in electron by making it a desktop application. Kindly help me. Whenever I tried starting it using electron I can't seem to have the results like in a web browser.



Here I provide the JS script and the HTML.






var numbers = ;
var Globaldistance;
$(function() {
var x1,y1,x2,y2;
var drawlines ;
var theCanvas = document.getElementById('paint');
var ctx = theCanvas.getContext('2d');
var img = document.getElementById("trya");
theCanvas.width = 500;
theCanvas.height = 500;

var canvasOffset = $('#paint').offset();
$('#paint').mousemove(function(e) {
if (drawlines) {
ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
ctx.strokeStyle = 'red';
ctx.lineWidth = 1;
ctx.beginPath();

ctx.moveTo(drawlines.x, drawlines.y);
ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
ctx.stroke();

document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
x2 = e.pageX;
y2 = e.pageY;

} numbers.push(x1,y1);
numbers.push(x2,y2);
document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
compute(numbers[0],numbers[1],numbers[2],numbers[3]);
});

$('#paint').mousedown(function(e) {
drawlines = {
x:e.pageX - canvasOffset.left,
y:e.pageY - canvasOffset.top

}
document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
x1= e.pageX;
y1= e.pageY;

});

$(window).mouseup(function() {
drawlines = null;
numbers = ;
});
});
function compute(a,b,c,d){
var x2x1 = c - a;
var y2y1 = d - b;
var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
document.getElementById("test").innerHTML= Math.round(dist);
Globaldistance = dist;
}

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!doctype html>
<meta charset="utf-8">
<title>Test</title>
</head>

<body>
<div class="can">
<canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
</div>
<p id="hehe"></p>
<p id="haha"></p>
<p id="hihi"></p>
<p id="hoho"></p>
<p id="tra"></p>
<p id="test"></p>
<script src="measure.js" type="text/javascript" ></script>
</body>
</html>












share|improve this question



























    0















    I'm new to electron and somehow my JS script is not working in electron.
    Here is my Javascript .I would like to implement this code in electron by making it a desktop application. Kindly help me. Whenever I tried starting it using electron I can't seem to have the results like in a web browser.



    Here I provide the JS script and the HTML.






    var numbers = ;
    var Globaldistance;
    $(function() {
    var x1,y1,x2,y2;
    var drawlines ;
    var theCanvas = document.getElementById('paint');
    var ctx = theCanvas.getContext('2d');
    var img = document.getElementById("trya");
    theCanvas.width = 500;
    theCanvas.height = 500;

    var canvasOffset = $('#paint').offset();
    $('#paint').mousemove(function(e) {
    if (drawlines) {
    ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
    ctx.strokeStyle = 'red';
    ctx.lineWidth = 1;
    ctx.beginPath();

    ctx.moveTo(drawlines.x, drawlines.y);
    ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
    ctx.stroke();

    document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
    document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
    x2 = e.pageX;
    y2 = e.pageY;

    } numbers.push(x1,y1);
    numbers.push(x2,y2);
    document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
    compute(numbers[0],numbers[1],numbers[2],numbers[3]);
    });

    $('#paint').mousedown(function(e) {
    drawlines = {
    x:e.pageX - canvasOffset.left,
    y:e.pageY - canvasOffset.top

    }
    document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
    document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
    x1= e.pageX;
    y1= e.pageY;

    });

    $(window).mouseup(function() {
    drawlines = null;
    numbers = ;
    });
    });
    function compute(a,b,c,d){
    var x2x1 = c - a;
    var y2y1 = d - b;
    var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
    document.getElementById("test").innerHTML= Math.round(dist);
    Globaldistance = dist;
    }

    <html>
    <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <!doctype html>
    <meta charset="utf-8">
    <title>Test</title>
    </head>

    <body>
    <div class="can">
    <canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
    </div>
    <p id="hehe"></p>
    <p id="haha"></p>
    <p id="hihi"></p>
    <p id="hoho"></p>
    <p id="tra"></p>
    <p id="test"></p>
    <script src="measure.js" type="text/javascript" ></script>
    </body>
    </html>












    share|improve this question

























      0












      0








      0








      I'm new to electron and somehow my JS script is not working in electron.
      Here is my Javascript .I would like to implement this code in electron by making it a desktop application. Kindly help me. Whenever I tried starting it using electron I can't seem to have the results like in a web browser.



      Here I provide the JS script and the HTML.






      var numbers = ;
      var Globaldistance;
      $(function() {
      var x1,y1,x2,y2;
      var drawlines ;
      var theCanvas = document.getElementById('paint');
      var ctx = theCanvas.getContext('2d');
      var img = document.getElementById("trya");
      theCanvas.width = 500;
      theCanvas.height = 500;

      var canvasOffset = $('#paint').offset();
      $('#paint').mousemove(function(e) {
      if (drawlines) {
      ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
      ctx.strokeStyle = 'red';
      ctx.lineWidth = 1;
      ctx.beginPath();

      ctx.moveTo(drawlines.x, drawlines.y);
      ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
      ctx.stroke();

      document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
      document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
      x2 = e.pageX;
      y2 = e.pageY;

      } numbers.push(x1,y1);
      numbers.push(x2,y2);
      document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
      compute(numbers[0],numbers[1],numbers[2],numbers[3]);
      });

      $('#paint').mousedown(function(e) {
      drawlines = {
      x:e.pageX - canvasOffset.left,
      y:e.pageY - canvasOffset.top

      }
      document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
      document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
      x1= e.pageX;
      y1= e.pageY;

      });

      $(window).mouseup(function() {
      drawlines = null;
      numbers = ;
      });
      });
      function compute(a,b,c,d){
      var x2x1 = c - a;
      var y2y1 = d - b;
      var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
      document.getElementById("test").innerHTML= Math.round(dist);
      Globaldistance = dist;
      }

      <html>
      <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!doctype html>
      <meta charset="utf-8">
      <title>Test</title>
      </head>

      <body>
      <div class="can">
      <canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
      </div>
      <p id="hehe"></p>
      <p id="haha"></p>
      <p id="hihi"></p>
      <p id="hoho"></p>
      <p id="tra"></p>
      <p id="test"></p>
      <script src="measure.js" type="text/javascript" ></script>
      </body>
      </html>












      share|improve this question














      I'm new to electron and somehow my JS script is not working in electron.
      Here is my Javascript .I would like to implement this code in electron by making it a desktop application. Kindly help me. Whenever I tried starting it using electron I can't seem to have the results like in a web browser.



      Here I provide the JS script and the HTML.






      var numbers = ;
      var Globaldistance;
      $(function() {
      var x1,y1,x2,y2;
      var drawlines ;
      var theCanvas = document.getElementById('paint');
      var ctx = theCanvas.getContext('2d');
      var img = document.getElementById("trya");
      theCanvas.width = 500;
      theCanvas.height = 500;

      var canvasOffset = $('#paint').offset();
      $('#paint').mousemove(function(e) {
      if (drawlines) {
      ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
      ctx.strokeStyle = 'red';
      ctx.lineWidth = 1;
      ctx.beginPath();

      ctx.moveTo(drawlines.x, drawlines.y);
      ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
      ctx.stroke();

      document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
      document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
      x2 = e.pageX;
      y2 = e.pageY;

      } numbers.push(x1,y1);
      numbers.push(x2,y2);
      document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
      compute(numbers[0],numbers[1],numbers[2],numbers[3]);
      });

      $('#paint').mousedown(function(e) {
      drawlines = {
      x:e.pageX - canvasOffset.left,
      y:e.pageY - canvasOffset.top

      }
      document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
      document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
      x1= e.pageX;
      y1= e.pageY;

      });

      $(window).mouseup(function() {
      drawlines = null;
      numbers = ;
      });
      });
      function compute(a,b,c,d){
      var x2x1 = c - a;
      var y2y1 = d - b;
      var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
      document.getElementById("test").innerHTML= Math.round(dist);
      Globaldistance = dist;
      }

      <html>
      <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!doctype html>
      <meta charset="utf-8">
      <title>Test</title>
      </head>

      <body>
      <div class="can">
      <canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
      </div>
      <p id="hehe"></p>
      <p id="haha"></p>
      <p id="hihi"></p>
      <p id="hoho"></p>
      <p id="tra"></p>
      <p id="test"></p>
      <script src="measure.js" type="text/javascript" ></script>
      </body>
      </html>








      var numbers = ;
      var Globaldistance;
      $(function() {
      var x1,y1,x2,y2;
      var drawlines ;
      var theCanvas = document.getElementById('paint');
      var ctx = theCanvas.getContext('2d');
      var img = document.getElementById("trya");
      theCanvas.width = 500;
      theCanvas.height = 500;

      var canvasOffset = $('#paint').offset();
      $('#paint').mousemove(function(e) {
      if (drawlines) {
      ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
      ctx.strokeStyle = 'red';
      ctx.lineWidth = 1;
      ctx.beginPath();

      ctx.moveTo(drawlines.x, drawlines.y);
      ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
      ctx.stroke();

      document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
      document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
      x2 = e.pageX;
      y2 = e.pageY;

      } numbers.push(x1,y1);
      numbers.push(x2,y2);
      document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
      compute(numbers[0],numbers[1],numbers[2],numbers[3]);
      });

      $('#paint').mousedown(function(e) {
      drawlines = {
      x:e.pageX - canvasOffset.left,
      y:e.pageY - canvasOffset.top

      }
      document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
      document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
      x1= e.pageX;
      y1= e.pageY;

      });

      $(window).mouseup(function() {
      drawlines = null;
      numbers = ;
      });
      });
      function compute(a,b,c,d){
      var x2x1 = c - a;
      var y2y1 = d - b;
      var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
      document.getElementById("test").innerHTML= Math.round(dist);
      Globaldistance = dist;
      }

      <html>
      <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!doctype html>
      <meta charset="utf-8">
      <title>Test</title>
      </head>

      <body>
      <div class="can">
      <canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
      </div>
      <p id="hehe"></p>
      <p id="haha"></p>
      <p id="hihi"></p>
      <p id="hoho"></p>
      <p id="tra"></p>
      <p id="test"></p>
      <script src="measure.js" type="text/javascript" ></script>
      </body>
      </html>





      var numbers = ;
      var Globaldistance;
      $(function() {
      var x1,y1,x2,y2;
      var drawlines ;
      var theCanvas = document.getElementById('paint');
      var ctx = theCanvas.getContext('2d');
      var img = document.getElementById("trya");
      theCanvas.width = 500;
      theCanvas.height = 500;

      var canvasOffset = $('#paint').offset();
      $('#paint').mousemove(function(e) {
      if (drawlines) {
      ctx.clearRect(0,0,theCanvas.width,theCanvas.height);
      ctx.strokeStyle = 'red';
      ctx.lineWidth = 1;
      ctx.beginPath();

      ctx.moveTo(drawlines.x, drawlines.y);
      ctx.lineTo(e.pageX - canvasOffset.left, e.pageY - canvasOffset.top);
      ctx.stroke();

      document.getElementById("hehe").innerHTML= "Page X2: "+e.pageX;
      document.getElementById("haha").innerHTML= "Page Y2: "+e.pageY;
      x2 = e.pageX;
      y2 = e.pageY;

      } numbers.push(x1,y1);
      numbers.push(x2,y2);
      document.getElementById("tra").innerHTML= "Coordinates in x1 y1 x2 y2 respectively : "+numbers[0]+" "+numbers[1]+" "+numbers[2]+" "+numbers[3];
      compute(numbers[0],numbers[1],numbers[2],numbers[3]);
      });

      $('#paint').mousedown(function(e) {
      drawlines = {
      x:e.pageX - canvasOffset.left,
      y:e.pageY - canvasOffset.top

      }
      document.getElementById("hihi").innerHTML= "Page X1: "+e.pageX;
      document.getElementById("hoho").innerHTML= "Page Y1: "+e.pageY;
      x1= e.pageX;
      y1= e.pageY;

      });

      $(window).mouseup(function() {
      drawlines = null;
      numbers = ;
      });
      });
      function compute(a,b,c,d){
      var x2x1 = c - a;
      var y2y1 = d - b;
      var dist = Math.sqrt(x2x1 * x2x1 + y2y1 *y2y1);
      document.getElementById("test").innerHTML= Math.round(dist);
      Globaldistance = dist;
      }

      <html>
      <head>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!doctype html>
      <meta charset="utf-8">
      <title>Test</title>
      </head>

      <body>
      <div class="can">
      <canvas id="paint" style="border:1px solid #d3d3d3;"></canvas>
      </div>
      <p id="hehe"></p>
      <p id="haha"></p>
      <p id="hihi"></p>
      <p id="hoho"></p>
      <p id="tra"></p>
      <p id="test"></p>
      <script src="measure.js" type="text/javascript" ></script>
      </body>
      </html>






      javascript electron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 5:24









      Khristian MoralesKhristian Morales

      94




      94
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001601%2fmouse-eventx-and-y-coordinates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001601%2fmouse-eventx-and-y-coordinates%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$