mimic-sussex / sema

Sema – A Playground for Live Coding Music and Machine Learning
https://sema.codes
MIT License
153 stars 51 forks source link

Erratic mouse input coordinate readings over CodeMirror #280

Closed frantic0 closed 3 years ago

frantic0 commented 3 years ago

Here's the change that corrects the bug.

// const x = e.offsetX/window.innerWidth;
// const y = e.offsetY/window.innerHeight;
const x = e.pageX/window.innerWidth;
const y = e.pageY/window.innerHeight;

From https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent

MouseEvent.offsetX – The X coordinate of the mouse pointer relative to the position of the padding edge of the target node.

MouseEvent.pageX – The X coordinate of the mouse pointer relative to the whole document.