2016-09-26 30 views
1

我试图调用本机SVG函数,但浏览器正在抱怨我的rect参数不是SVGRect。我不确定是否有任何区别,SVGRect似乎是一个界面,但它不应该仍然接受rect节点?参数1不属于'SVGRect'类型

HTML

<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="884" style="opacity: 1;"> 
<rect class="overlay" width="1920" height="884"></rect> 
</svg> 

JS

创作:

var svg = d3.select('body') 
     .append("svg") 
      .attr('xmlns',d3.ns.prefix.svg) 
      .attr("width", width) 
      .attr("height",height) 

    svg.append('svg:rect') 
     .attr('class','overlay') 
     .attr("width", width) 
     .attr("height",height) 

后来:

var svg = d3.select('svg').node() 
var rect = d3.select('rect.overlay').node(); 
var intersect = svg.checkIntersection(this,rect) 

上面的代码会抛出错误Uncaught TypeError: Failed to execute 'getEnclosureList' on 'SVGSVGElement': parameter 1 is not of type 'SVGRect'.

+1

一个SVGRect和一个矩形元素是完全不同的东西。前者不能被渲染,只能作为数据持有者,后者是渲染的标记对象。当API期待另一个时,你不能混用一个。 –

+0

感谢您的澄清。如何获得反映我的'rect'元素属性的'SVGRect'对象的引用? –

回答

相关问题