I recently had a similar project. I am not sure how well this works with the mobile scrollable stuff you have going on, but the marking math would probably be similar. I did not find a suitable library either and ended up writing my own. I don't have that code, but it is relatively straight forward.
There is not really much magic to it. Basically, you want to find the click coordinates (event.pageX
and event.pageY
), adjust for the image's .offset().left
and offset().top
values, and then compare them to the image's height
and width
to calculate the coordinates as a percentage against the image.
The ratio x/y values become important if you ever want to resize the image and have the marks remain in place. You just want to make sure the image in inside a container with relative
positioning and you can recalculate explicit x/y values as needed.
Something like:
var marks = [];
var $img = $("img");
$img.on("click",function(e){
marks.push({
x: (e.pageX - $img.offset().left) / $img.width(),
y: (e.pageY - $img.offset().top) / $img.width(),
id: marks.length
});
drawMarks();
});
function drawMarks(){
var mCount = marks.length;
$(".mark").remove();
while(mCount--){
var mark = marks[mCount];
$("<div class='mark' >")
.data("id", mark.id)
.appendTo('.holder')
.css("top", mark.y * $img.width() + "px")
.css("left", mark.x * $img.width() + "px");
}
}