Below the Radar
Below the Radar

Reputation: 7635

Convert mouse coordinates from one window size to fit into another window size

Imagine two different windows with the same page loaded but different sizes. I want to pass the mouse coordinates from one window to the second window in order to point to the same location in both page.

How can I convert the mouse coordinates of the first window to fit in the second?

Upvotes: 0

Views: 51

Answers (1)

CoderPi
CoderPi

Reputation: 13211

otherMouseX = thisMouseX / thisWindowWidth * otherWindowWidth

and the same for mouse y

Upvotes: 2

Related Questions