Skip to content

Instantly share code, notes, and snippets.

@joehwang
Created May 31, 2017 17:02
Show Gist options
  • Save joehwang/1da4adf9ac7fd47acec5d5b3fda2a5ff to your computer and use it in GitHub Desktop.
Save joehwang/1da4adf9ac7fd47acec5d5b3fda2a5ff to your computer and use it in GitHub Desktop.
轉換座標系
function oMousePos(target, evt) {
var rect = target.getBoundingClientRect();
console.log( Math.round(evt.clientX - rect.left))
return {
x: Math.round(evt.clientX - rect.left),
y: Math.round(evt.clientY - rect.top)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment