Skip to content

Instantly share code, notes, and snippets.

@riix
Created July 24, 2012 05:44
Show Gist options
  • Save riix/3168255 to your computer and use it in GitHub Desktop.
Save riix/3168255 to your computer and use it in GitHub Desktop.
마우스 커서 좌표 탐색, Get X, Y Coordinates of Mouse Within Box with jQuery
// 본문 마우스 커서 좌표 탐색
$(function(){
$(window).mousemove(function(event){
//display the x and y axis values inside the P element
$('p').html('X Axis : ' + event.pageX + ' | Y Axis ' + event.pageY);
});
});
<p>Ready...</p>
// 객체 내 마우스 커서 상대 좌표 탐색
$("#demo-box").click(function(event) {
var offset = $(this).offset();
var relativeX = (event.pageX - offset.left);
var relativeY = (event.pageY - offset.top);
alert("X: " + relativeX + " Y: " + relativeY);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment