How about saving not only the x
/y
coordinates of the click but also the width
/height
of the view-port. That way you can get the position of the click relative to the view-port and calculate where on the content the click actually occured:
$(document).on('click', function (event) {
var x = event.pageX,
y = event.pageY,
w = $(window).width(),
h = $(window).height();
});
You could optimize this by only getting the view-port dimension when they change:
var windowWidth = 0,
windowHeight = 0;
$(window).on('resize', function () {
windowWidth = $(this).width();
windowHeight = $(this).height();
}).trigger('resize');//this .trigger will get the dimensions on page-load
$(document).on('click', function (event) {
var x = event.pageX,
y = event.pageY,
w = windowWidth,
h = windowHeight;
});
Update
For pages that are centered you could get the coordinate from the center of the view-port:
var windowWidth = 0,
windowHeight = 0;
$(window).on('resize', function () {
windowWidth = $(this).width();
windowHeight = $(this).height();
}).trigger('resize');//this .trigger will get the dimensions on page-load
$(document).on('click', function (event) {
var x = (event.pageX - (windowWidth / 2)),
y = event.pageY;
});
This will result in positive x
dimensions for anything on the right side of the page and negative x
dimensions for anything on the left side of the page.
Here is a demo: http://jsfiddle.net/aWBFM/