←back to thread

293 points ulrischa | 1 comments | | HN request time: 0.001s | source
Show context
account42 ◴[] No.42174070[source]
Why are websites getting mouse position in screen coordinates in the first place?
replies(8): >>42174192 #>>42174200 #>>42174236 #>>42174247 #>>42174483 #>>42174549 #>>42174581 #>>42177418 #
jazzyjackson ◴[] No.42174192[source]
If you're reacting to click events, you might want to know the coordinates of where you're clicking. I mostly use this for click and drag stuff since you can get the delta between events and update position of the thing being dragged.

As for why they're checking for coordinates instead of checking for event.type is beyond me. Still I appreciate the write up, it is a good puzzle and relatable to come across code you didn't write and ask, why is it important that the click coordinate is nonzero? Why can't we just check that event.target is the button we want to activate? Why are we using JavaScript at all when a details/summary tag would do the same job?

replies(1): >>42175606 #
1. yarg ◴[] No.42175606[source]
Relative coordinates sure, but why would you need the absolute position?

I'm with you on the second point - as unlikely as it is for the click to occur at the origin, it's still a legitimate value being abused as an indicator of something that might not actually be true - quite frankly the code was bad to begin with, and it was still bad after the fix.