I am trying to insert an image in a div
based on where the user clicks. This seems to work fine, unless the div
is scrollable, and then the position of the image remains the same regardless of where we've scrolled to. The image should remain in the same place relative to the content within the div
.
Code:
$("#a").on("click",function(e){
var top=e.pageY-$(this).position().top,
left=e.pageX-$(this).position().left;
$('.imgajoutee').remove();
$(this).append("<img src='https://upload.wikimedia.org/wikipedia/commons/0/0c/Dive_hand_signal_OK_1.png' class='imgajoutee' style='top:"+top+"px;left:"+left+"px;'/>");
});