Scroll through the block objects and determine what was clicked like this:
var y = e.pageY,
x = e.pageX,
cOffset = $(c).offset(),
clickedUnit;
x = x - cOffset.top;
y = y - cOffset.left;
for (var i = -1, l = units.length, unit; ++i < l;) {
unit = units[i];
if (
y > unit.y && y < unit.y + unit.height &&
x > unit.x && x < unit.x + unit.width
) {
clickedUnit = unit;
break;
}
}
Please note: this will not handle complex intersecting objects or problems with z-indexes, etc ... just a starting point.
James source
share