我尝试调用原生SVG函数,但浏览器抱怨我的rect
参数不是SVGRect
。我不确定是否存在任何差异,SVGRect
似乎是一个界面,但它是否仍然接受rect
节点?
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'.
答案 0 :(得分:3)
原来你可以使用边界框......在官方文档中不是很清楚,或者我可能不太了解这种语言。
https://www.w3.org/TR/SVG/struct.html#__svg__SVGSVGElement__checkIntersection
add_executable
给我我需要的结果。