html dragging get mouse position

Solutions on MaxInterview for html dragging get mouse position by the best coders in the world

showing results for - "html dragging get mouse position"
Luis
28 Oct 2017
1    >>> import pyautogui
2    >>> screenWidth, screenHeight = pyautogui.size() # Returns two integers, the width and height of the screen. (The primary monitor, in multi-monitor setups.)
3    >>> currentMouseX, currentMouseY = pyautogui.position() # Returns two integers, the x and y of the mouse cursor's current position.
4    >>> pyautogui.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.
5    >>> pyautogui.click() # Click the mouse at its current location.
6    >>> pyautogui.click(200, 220) # Click the mouse at the x, y coordinates 200, 220.
7    >>> pyautogui.move(None, 10)  # Move mouse 10 pixels down, that is, move the mouse relative to its current position.
8    >>> pyautogui.doubleClick() # Double click the mouse at the
9    >>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad) # Use tweening/easing function to move mouse over 2 seconds.
10    >>> pyautogui.write('Hello world!', interval=0.25)  # Type with quarter-second pause in between each key.
11    >>> pyautogui.press('esc') # Simulate pressing the Escape key.
12    >>> pyautogui.keyDown('shift')
13    >>> pyautogui.write(['left', 'left', 'left', 'left', 'left', 'left'])
14    >>> pyautogui.keyUp('shift')
15    >>> pyautogui.hotkey('ctrl', 'c')
16
Gianluca
12 Feb 2017
1import pyautogui
2
3#pyautogui.moveTo(X, Y, Seconds)
4pyautogui.moveTo(100, 100, 2) #Move to X=100, Y=100 over a 2 seconds period
Alycia
15 Apr 2018
1<!DOCTYPE html>
2<html>
3
4<head>
5  <meta name="viewport" 
6        content="width=device-width, 
7        initial-scale=1.0, 
8        user-scalable=no" />
9  <title>Drag/Drop/Bounce</title>
10  <style>
11    #container {
12      width: 100%;
13      height: 400px;
14      background-color: #333;
15      display: flex;
16      align-items: center;
17      justify-content: center;
18      overflow: hidden;
19      border-radius: 7px;
20      touch-action: none;
21    }
22    #item {
23      width: 100px;
24      height: 100px;
25      background-color: rgb(245, 230, 99);
26      border: 10px solid rgba(136, 136, 136, .5);
27      border-radius: 50%;
28      touch-action: none;
29      user-select: none;
30    }
31    #item:active {
32      background-color: rgba(168, 218, 220, 1.00);
33    }
34    #item:hover {
35      cursor: pointer;
36      border-width: 20px;
37    }
38  </style>
39</head>
40
41<body>
42
43  <div id="outerContainer">
44    <div id="container">
45      <div id="item">
46
47      </div>
48    </div>
49  </div>
50
51  <script>
52    var dragItem = document.querySelector("#item");
53    var container = document.querySelector("#container");
54
55    var active = false;
56    var currentX;
57    var currentY;
58    var initialX;
59    var initialY;
60    var xOffset = 0;
61    var yOffset = 0;
62
63    container.addEventListener("touchstart", dragStart, false);
64    container.addEventListener("touchend", dragEnd, false);
65    container.addEventListener("touchmove", drag, false);
66
67    container.addEventListener("mousedown", dragStart, false);
68    container.addEventListener("mouseup", dragEnd, false);
69    container.addEventListener("mousemove", drag, false);
70
71    function dragStart(e) {
72      if (e.type === "touchstart") {
73        initialX = e.touches[0].clientX - xOffset;
74        initialY = e.touches[0].clientY - yOffset;
75      } else {
76        initialX = e.clientX - xOffset;
77        initialY = e.clientY - yOffset;
78      }
79
80      if (e.target === dragItem) {
81        active = true;
82      }
83    }
84
85    function dragEnd(e) {
86      initialX = currentX;
87      initialY = currentY;
88
89      active = false;
90    }
91
92    function drag(e) {
93      if (active) {
94      
95        e.preventDefault();
96      
97        if (e.type === "touchmove") {
98          currentX = e.touches[0].clientX - initialX;
99          currentY = e.touches[0].clientY - initialY;
100        } else {
101          currentX = e.clientX - initialX;
102          currentY = e.clientY - initialY;
103        }
104
105        xOffset = currentX;
106        yOffset = currentY;
107
108        setTranslate(currentX, currentY, dragItem);
109      }
110    }
111
112    function setTranslate(xPos, yPos, el) {
113      el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)";
114    }
115  </script>
116</body>
117
118</html>
Angelo
03 Jan 2019
1//  JavaScript
2
3document.addEventListener("dragover", function(e){
4    e = e || window.event;
5    var dragX = e.pageX, dragY = e.pageY;
6
7    console.log("X: "+dragX+" Y: "+dragY);
8}, false);
9
10//  jQuery
11
12$("body").bind("dragover", function(e){
13    var dragX = e.pageX, dragY = e.pageY;
14
15    console.log("X: "+dragX+" Y: "+dragY);
16});
similar questions
queries leading to this page
html dragging get mouse position