Javascript SVG路径图
我尝试的是使用SVG javascript中的路径绘制。下面的代码适用于SVG javascript中的多段线,我想对SVG中的路径使用相同的代码 我得到的错误是:Javascript SVG路径图,javascript,svg,Javascript,Svg,我尝试的是使用SVG javascript中的路径绘制。下面的代码适用于SVG javascript中的多段线,我想对SVG中的路径使用相同的代码 我得到的错误是: > Uncaught TypeError: Cannot read property 'call' of undefined > at SVG.PathArray.parse (svg.js:889) >at SVG.PathArray.SVG.Array (svg.js:433) >at new SVG.P
> Uncaught TypeError: Cannot read property 'call' of undefined
> at SVG.PathArray.parse (svg.js:889)
>at SVG.PathArray.SVG.Array (svg.js:433)
>at new SVG.PathArray (svg.js:686)
>at initializer.plot (svg.js:4413)
>at create.path (svg.js:4454)
>at create_New_Path (javascript_mainSVG.js:203)
>at HTMLDivElement.pointerDown (javascript_mainSVG.js:97)
我使用的库来自svgjs.dev
这是触发事件pointerdown、pointermove和pointerup的三个函数
create_New_Path(event.pageX,event.pageY);
add_To_Current_Path(event.pageX,event.pageY);
end_Current_Path(event.pageX,event.pageY);
function end_Current_Path(x,y) {
arr = myPath.plot();
arr.value.push([x,y]);
myPath.plot(arr);
myPath = null;
}
创建新路径(x,y)“pointerdown”
添加到当前路径“pointermove”
结束当前路径“pointerup”
是否可以使用与多段线相同的代码。感觉它应该通过替换路径而不是多段线来工作。
event.pageX,ev.pageY
似乎应该是event
或ev
不工作@chrisg调用“push”函数时会出现类似的错误:未捕获类型错误:无法读取未定义的so的属性“call”,event.pageX
或ev.pageY
是否可能是未定义的
。。。?因为它几乎必须是那样的。这可能会导致其他问题。你能把你实际的事件处理程序代码添加到这个问题中吗?好吧,对不起@ChrisG,我的意思是我知道事件,而且总是这样,我只是在上面的代码中写错了。我总是使用和你说的相同的事件名称。它适用于多段线,但不适用于路径。
function add_To_Current_Path(x,y) {
arr = myPath.plot();
arr.value.push([x,y]);
myPath.plot(arr);
}
function end_Current_Path(x,y) {
arr = myPath.plot();
arr.value.push([x,y]);
myPath.plot(arr);
myPath = null;
}