I am currently learning and working in JavaScript and SVG, and I am new to this. Here is my script
I have a div that has SVG in it.
<div id "O_div">
<svg>
<line x1= "0" x2 = "0" y1 ="0" y2 ="0">
</line>
<svg>
</div>
Now I want to know the position of the mouse relative to my div, so I wrote the following code
odiv = document.querySelector('#O_div');
XOffset = $(Odiv).position().left;
YOffset = $(Odiv).position().top;
$('#O_div').mousemove(function(event) {
var mouseX = event.clientX - XOffset;
var mouseY = event.clientY - YOffset;
});
It is working fine. But the problem occurs when I add resizing functionality to my div using a resizable request. To resize my svg, I added the viewBox parameter to it. Now my svg looks like this:
<svg viewBox="0 0 450 154" preserveAspectRatio="xMinYMin meet">
</svg>
But now my mouse coordinate is not working fine, and my line is a little further from my mouse, and it goes far from my mouse when I increase the size of the div. Can someone kindly explain to me how I can calculate my offset positions when I have a view option in my svg.
, .