Created
July 24, 2012 05:44
-
-
Save riix/3168255 to your computer and use it in GitHub Desktop.
마우스 커서 좌표 탐색, Get X, Y Coordinates of Mouse Within Box with jQuery
This file contains hidden or 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
// 본문 마우스 커서 좌표 탐색 | |
$(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