所以我所拥有的是一个没有HTML的SVG-Document,而且在<defs>...</defs>-section中我有我的JavaScript.在其中,有一个创建椭圆弧的功能(虽然我只将它用于圆弧,在本例中,仅用于圆)和另一个使用前一种方法创建圆的功能.这可能不是现在最优雅的方式,但我稍后会考虑一下......
然而,现在,当我尝试通过createElement()Chrome和Firefox 进入创建新元素时,SVG-DOM-Object不包含该方法的错误.
这是代码:
var SVGObj = document.getElementById('canvas');
function Point(x, y) {
this.x = x;
this.y = y;
}
var ids = new Array();
ids.nextID = nextID;
function nextID() {
this.push(this.length);
return this.length;
}
function hypot(pointA, pointB) {
return Math.sqrt((pointA.x - pointB.x) * (pointA.x - pointB.x) + (pointA.y - pointB.y) * (pointA.y - pointB.y))
}
function arc(center, from, to, fill) {
if (hypot(center, from) == hypot(center, to))
radius = hypot(center, from);
else
return false;
var arch …Run Code Online (Sandbox Code Playgroud)