像这样的东西可以用来实现ckaufman的建议。
image1.click(function(e) {
var offset = $(this).offset(),
width = $(this).width(),
height = $(this).height(),
leftPercent = (e.clientX - offset.left)/width,
topPercent = (e.clientY - offset.top)/height;
// position marker image appropriately and
// store leftPercent and topPercent in database
});
然后要在同一图像的不同大小版本上设置标记的位置,您可以执行以下操作:
var leftPercent = .45, // from database
toppercent = .23
image2.load(function() {
var width = $(this).width(),
height = $(this).height(),
leftPosition = Math.round(leftPercent*width),
topPosition = Math.round(topPercent*height);
// set the marker position to leftPosition and topPosition
// note: this is relative to the top left of the main image
});