JavaScript How to print out a mouse drag distance in pixels using JavaScript/JQuery

I'm new to JS and JQuery, and I'm implementing a simple web app: I used 16 pictures to make a map (4x4 grid). When the user clicks or releases the mouse, the console prints out the mouse's X and Y position - I was able to do this.

If the user clicks and drags the mouse, I need to print out a drag distance in pixels. I did some research but wasn't able to find a satisfying answer. Most solutions involve lengthy manipulation of "canvas" and "context", which I'm not familiar with at all; is there a simple function in JQuery that allows you to change a pixel's color once you know its coordinates? Otherwise, how should I go about this problem?

Here's my code:

'use strict';

function printMousePos(e){
    var cursorX = e.clientX;
    var cursorY = e.clientY;
    console.log("X: " + cursorX + " Y: " + cursorY);
}
document.addEventListener("mouseup",printMousePos);
document.addEventListener("mousedown",printMousePos);
body{
     margin:0;
 }
.map img{
    float:left;
    width:25%;
}
<!DOCTYPE html>
<html>
<head lang="en">
    <link rel="stylesheet" type="text/css" target='_blank' href="map.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
    <script type="text/javascript" src="map.js"></script>
</head>
<body>
    <div class="map" >
        <img src="map_images/1.png">
        <img src="map_images/2.png">
        <img src="map_images/3.png">
        <img src="map_images/4.png">
    </div>
    <div class="map">
        <img src="map_images/5.png">
        <img src="map_images/6.png">
        <img src="map_images/7.png">
        <img src="map_images/8.png">
    </div>
    <div class="map">
        <img src="map_images/9.png">
        <img src="map_images/10.png">
        <img src="map_images/11.png">
        <img src="map_images/12.png">
    </div>
    <div class="map">
        <img src="map_images/13.png">
        <img src="map_images/14.png">
        <img src="map_images/15.png">
        <img src="map_images/16.png">
    </div>
</body>
</html>
Answer:1

I've created this little fancy jQuery Snippet to toggle the class of an element in an interval: setInterval(function(){$('.grid-item .slide-image').toggleClass('active')}, 800); The script works ...

I've created this little fancy jQuery Snippet to toggle the class of an element in an interval: setInterval(function(){$('.grid-item .slide-image').toggleClass('active')}, 800); The script works ...

  1. jquery toggle class onclick
  2. jquery toggle class animation
  3. jquery toggleclass not working
  4. jquery toggle class on hover
  5. jquery toggle class multiple
  6. jquery toggle class based on boolean
  7. jquery toggle class on button click
  8. jquery toggleclass delay
  9. jquery toggle class hide show
  10. jquery toggle class codepen
  11. jquery toggle class on scroll
  12. jquery toggle class condition
  13. jquery toggle class function
  14. jquery toggle class click
  15. jquery toggle class callback
  16. jquery toggle class by id
  17. jquery toggleclass off
  18. jquery toggle class visibility
  19. jquery toggle class this
  20. jquery toggle class on focus

I am trying to make the angular material directive to render vertically. I have tried using transform:rotate in the CSS but the slider starts behaving and rendering differently. md-slider { ...

I am trying to make the angular material directive to render vertically. I have tried using transform:rotate in the CSS but the slider starts behaving and rendering differently. md-slider { ...

  1. make angular material table responsive
  2. make angular material responsive
  3. make angular material input smaller
  4. how to make angular material dialog draggable
  5. how to make angular material table scrollable
  6. how to make angular material grid responsive
  7. make checkbox readonly angular material
  8. angular material make button smaller
  9. angular material make card clickable
  10. angular material make div scrollable
  11. angular material make icon bigger
  12. angular material make list scrollable
  13. angular material make button bigger
  14. angular material make table editable
  15. angular material make header sticky

Why does this transcluded directive repeat Name inside directive = Frank twice? I thought I understood transclusion but this has me confused. Here's a fiddle <div ng-app="myApp" ng-controller="...

Why does this transcluded directive repeat Name inside directive = Frank twice? I thought I understood transclusion but this has me confused. Here's a fiddle <div ng-app="myApp" ng-controller="...

I have two 16bit integer raw data. For example: High Word = 17142 (dec) or 0100001011110110 (binary) Low Word = 59759 (dec) or 1110100101111001 (binary) If you treat two word together as one 32bit ...

I have two 16bit integer raw data. For example: High Word = 17142 (dec) or 0100001011110110 (binary) Low Word = 59759 (dec) or 1110100101111001 (binary) If you treat two word together as one 32bit ...

  1. convert 16 bit integer to 32 bit integer
  2. convert 16 bit integer to floating point
  3. convert 16 bit integer to 8 bit integer
  4. convert 16 bit integer to ascii
  5. convert 16 bit integer to 32 bit float
  6. convert 16 bit integer to hex
  7. convert 16 bit to integer
  8. convert 16 bit signed integer to decimal
  9. convert 16 bit signed integer to binary
  10. convert float to 16 bit integer
  11. convert integer to 16 bit binary
  12. convert number to 16 bit integer
  13. convert integer to 16 bit binary java