When you click on an element, you need to start tracking the position of the mouse cursor, the place where you clicked must have coordinates 0; 0. Found a way to track the cursor position relative to the screen, but I donβt know how to do it relative to the pressed place. It is advisable to show on the basis of my code, since its already familiar and understandable))
position = false; $(document).mousedown(function() { position = true; }) $(document).mouseup(function() { position = false; }) document.onmousemove = mousemove; function mousemove(event) { if (position) { mouse_x = y = 0; if (document.attachEvent != null) { mouse_x = window.event.clientX; mouse_y = window.event.clientY; } else if (!document.attachEvent && document.addEventListener) { mouse_x = event.clientX; mouse_y = event.clientY; } console.log('x=' + mouse_x + '; ' + 'y=' + mouse_y); } } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <h1>ΠΠ°ΠΆΠΌΠΈ ΠΈ Π΄Π΅ΡΠΆΠΈ</h1>