用svg画了一个1000宽度的矩形, 我想鼠标移动时获得指针在矩形中的相对位置,请问要怎么编写?
比如水平移动到中间, x就是500这样子, 代码如下:
<svg version="1.1" baseProfile="full" width="100%" height="200" viewBox="0 0 1020 200"
xmlns="http://www.w3.org/2000/svg" style="border: 1px solid red">
<g transform="translate(10,0)">
<rect x="0" width="1000" height="90%" fill="#33546F" onMouseMove="handleMouseMove(evt)" />
<line x1="100" x2="100" y1="0" y2="90%" stroke="#ccc" id="line" />
</g>
</svg>
你得对一个不变的元素进行鼠标事件监听,不然不乱套了