问题
Hi I'm using Jquery's mouse position to find the position of the page.
I would like it to have it behave more like latitude and longitude coordinates.
$().mousemove(function(e){
$('#detect').html( e.pageX + '° N, '+ e.pageY + '° E' );
});
I realise this is not true latitude and longitude coordinates. The box would be the webpage, and 0 is absolute middle of the webpage. Moving the mouse into the N/E area would produce this result.

Any help would be appreciated. Thanks.
回答1:
Javascript:
var screenX = $(document).width() / 2;
var screenY = $(document).height() / 2;
$(document).mousemove(function(e){
var apX = screenX - e.pageX;
var apY = screenY - e.pageY;
var latT = (apY>=0) ? 'N' : 'S';
var lonT = (apX>=0) ? 'W' : 'E';
apX = Math.round(Math.abs(apX));
apY = Math.round(Math.abs(apY));
$('#detect').html( apX + 'px '+ latT +', '+ apY + 'px '+ lonT );
});
You can find a test on http://jsfiddle.net/nvwzH/
来源:https://stackoverflow.com/questions/8500111/mouse-position-count