-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to get mouse coordinates without mouse moving #10584
Comments
could you elaborate more on the intended use case? |
No mouse moving. The task is to determine over which element the cursor is. It is impossible. |
that doesn't explain the why |
Because your code can't wait for some event. You need the coordinates right away. |
It's possible for a page to lose focus and then regain focus with the mouse in a different position, without receiving any mouse event about the position change. For example, in Firefox on Cinnamon, pressing the Win/Super key, moving the mouse, and pressing Escape will do this. I can think of a cosmetic use case for detecting such a position change: if the page is using Javascript to animate a cursor, the animation won't match the real cursor position until a mouse event comes in. However, this use case could be supported by just guaranteeing mousemove events in more situations, rather than adding a whole different API. I can't think of any actual use case for a separate API. |
|
You'll have to explain your actual use case if you want anyone to follow along. Why would you simultaneously: |
To use |
Many low level libraries will expose mouse cursor by events. The issue here is not that the cursor position isn't accessible from anywhere but that no mouse event occurs when the tab is refocused. I believe I have seen it mentioned elsewhere that not being able to see the mouse position before the user has hovered over the tab is intentional and will not be addressed. Rather than set up and event listener to delete it again, keep one event listener on and use it to update a variable that you can read at any time. |
Yes, events are generated only when the cursor is inside the page. Because we use
It is very bad. To handle events a whole day to use it several times. These events consume a lot of performance. 1 more reason to add this. |
Have you measured this performance change? |
Yes, the cursor lags a bit. |
From my own experiences, I believe it far more likely that whatever lag you're observing is a symptom of some performance bug in your code, or some misunderstanding of how to use events, not because of the performance cost of one simple mousemove handler. Implementers (Apple, Google, Mozilla) rarely add new API just for performance reasons, and certainly not without data. If there actually is an issue here (which I'll admit I continue to doubt), you'll need to show a reproducible, measurable demonstration of the problem, not an anecdote. |
I came here to suggest a new useful feature, not to get a solution (because there is nothing about it that I don't know). But I know that you (WHATWG) will add things which will be used by 1% of programmers (some very specific things) instead of adding general useful things. |
What problem are you trying to solve?
Getting mouse coordinates at some concrete moment.
What solutions exist today?
No response
How would you solve it?
For example, something like
navigator.mouse.clientX
,navigator.mouse.clientY
.Anything else?
No response
The text was updated successfully, but these errors were encountered: