Similarly, to get the position on the Y-axis, we subtract the offsetTop property from the clientY property of the MouseEvent object. As you move your cursor (aka, mouse pointer) around on this webpage, the X and Y coordinates are indicated in a DHTML layer near the cursor. We subtract the offsetLeft property of the element from the clientX property of the MouseEvent object to get the position on the X-axis relative to the element. For example, position (0, 0) will be at the top left of the element, not the viewport: The current mouse position relative to the element is shown. With these coordinates, you can execute other functions and lines of code based on where the cursor is located on the page. Now the resulting X and Y coordinates will be relative to the element. mouse.getpos(), which returns an ordered pair of coordinates of the point where the mouse cursor is currently located. At this point, the solution for transforming the mouse cursor into canvas space is simple, subtract the translation amount from the mouse cursor position. Const globalMousePosText = document.getElementById('global-mouse-pos') Ĭonst localMousePosText = document.getElementById('local-mouse-pos')
0 Comments
Leave a Reply. |