Reputation: 10878
When a screen is zoomed, the event.screenX
and event.screenY
of a MouseEvent
are not equatable to px offsets from the top and bottom. They fall slowly behind when zoomed out, and jump slowly ahead when zoomed in.
How can I take screen zoom into account to make an element follow my cursor?
Upvotes: 1
Views: 216
Reputation: 10878
The trick is to not use screenX
and screenY
, and instead use clientX
and clientY
. These measurements are zoom relative, and also viewport relative (so they will still work if your code is embedded in a viewport).
Upvotes: 2