I have a webpage with a box that can be moved around on the page (via JavaScript) that contains many large SVG diagrams and thus needs a scrollbar to allow viewing all content in it. I need to know the coordinate the user clicks inside the box; the distance between the top-left corner and the click position inside the inner content area. I only know MouseEvent.pageX, clientX and screenX but these do not provide the correct result. Reduced to the minimum to show the situation:
<div class="content">
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.<br>
The content is to wide to show in this box.
</div>
And the corresponding CSS:
.content {
border: solid 1px;
height: 100px;
width: 100px;
overflow: auto;
top: 50px;
left: 200px;
position: absolute;
}
Answer: Thanks Yogi and flowton!
The combination of event.offsetX/Y + event.target.scrollLeft/Top did the trick!