Created
August 23, 2016 01:46
-
-
Save ktsn/6866f87cfa6487fe355e1e01d79bfca1 to your computer and use it in GitHub Desktop.
特定の要素上でマウスイベントが発生した時に、その要素におけるマウスの座標を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
el.addEventListener('mousemove', event => { | |
const rect = event.currentTarget.getBoundingClientRect() | |
const pos = { | |
left: event.clientX - rect.left, | |
top: event.clientY - rect.top | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
client(X|Y)
ページの左上を基準としたマウスの座標getBoundingClientRect
ページの左上を基準とした対象とする要素の左上の座標