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'.
一個SVGRect和一個矩形元素是完全不同的東西。前者不能被渲染,只能作爲數據持有者,後者是渲染的標記對象。當API期待另一個時,你不能混用一個。 –
感謝您的澄清。如何獲得反映我的'rect'元素屬性的'SVGRect'對象的引用? –