riix
7/24/2012 - 5:44 AM

마우스 커서 좌표 탐색, Get X, Y Coordinates of Mouse Within Box with jQuery

마우스 커서 좌표 탐색, 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);
});