在Chrome中,可调整大小的SVG的鼠标坐标变换不正确(使用视口)

在Chrome中,可调整大小的SVG的鼠标坐标变换不正确(使用视口),svg,Svg,例如: 光标位于鼠标移动矩形的中心-确定 不在中心的铬-坏 Chrome中的getScreenCTM函数(svg元素)是否存在缺陷 在Firefox中,Opera all ok我测试了脚本,尝试注释第一个svg元素设置宽度和高度属性的部分@如果成功了,你应该给它一个答案!还有,你知道为什么吗? var width = 960, height = 500; // Append an SVG element var svg = d3.select('body') .append('s

例如:

光标位于鼠标移动矩形的中心-确定

不在中心的铬-坏

Chrome中的getScreenCTM函数(svg元素)是否存在缺陷


在Firefox中,Opera all ok

我测试了脚本,尝试注释第一个svg元素设置宽度和高度属性的部分@如果成功了,你应该给它一个答案!还有,你知道为什么吗?
    var width = 960,  height = 500;

// Append an SVG element
var svg = d3.select('body')
  .append('svg')
  .attr('viewBox', '0 0 ' + width + ' ' + height)
  .attr('width', width)
  .attr('height', height);

svg.append("rect")
.attr('id', 'followMe')
.attr('width', 20)
.attr('height', 20)
.attr('fill', 'peachPuff')
.attr('stroke', 'crimson');

var followRectElement = document.getElementById('followMe');

window.addEventListener('mousemove', function(event) {

        var svgPoint = svg[0][0].createSVGPoint();

        svgPoint.x = event.clientX;
        svgPoint.y = event.clientY;

        svgPoint = svgPoint.matrixTransform(followRectElement.getScreenCTM().inverse());

        followRectElement.setAttribute('x', svgPoint.x - 10);
        followRectElement.setAttribute('y', svgPoint.y - 10);
    });