当我试图在一个html页面中使用两个库(rafael.js和paper.js)时,我得到了各种错误。
1。未捕获的ReferenceError: Raphael未定义。在文件"rafael.js"中,行:
var paper = Raphael(0, 0, 320, 200);
是错误的原因。但显然它是在html:
中导入的<head>
...
<script src="js/paper-full.js" type="text/javascript"></script>
<script src="js/mypaper.js" type="text/paperscript" canvas="myCanvas">
</head>
<body>
<script src="js/rafael.js" type="text/javascript"></script>
<canvas id='myCanvas' resize></canvas>
<script src="js/myrafael.js"></script>
...
</body>
2。未捕获的错误:无法找到id为"myCanvas"的画布,但画布在那里。这里是html:
<head>
...
<script src="js/rafael.js" type="text/javascript"></script>
<script src="js/paper-full.js" type="text/javascript"></script>
<script src="js/mypaper.js" type="text/paperscript" canvas="myCanvas">
</head>
<body>
<canvas id='myCanvas' resize></canvas>
<script src="js/myrafael.js"></script>
...
</body>
同样的错误也发生了,当我有拉斐尔和纸代码在一个。js文件("myrafaelpaper.js"),尽管事实上,myCanvas在那里:
<head>
...
<script src="js/rafael.js" type="text/javascript"></script>
<script src="js/paper-full.js" type="text/javascript"></script>
<script src="js/myrafaelpaper.js" type="text/paperscript" canvas="myCanvas">
</head>
<body>
<canvas id='myCanvas' resize></canvas>
<script src="js/myrafaelpaper.js"></script>
...
</body>
单独使用,它们可以正常工作。
"myrafaelpaper.js"在这里:
//rafael.js part
var paper = Raphael(0, 0, 320, 200);
var circle = paper.circle(0, 30, 50);
circle.attr("fill", "#f00");
console.log(circle.isPointInside(50, 30));
//paper.js part
var pathData = 'M100,50c0,27.614-22.386,50-50,50S0,77.614,0,50S22.386,0,50,0S100,22.386,100,50';
var path = new Path(pathData);
path.strokeColor = 'red';
path.strokeWidth = 5;
path.position+= new Point(100, 50);
path.segments[3].point.selected=true;
"myrafael.js"one_answers"mypaper.js"的内容是类似的
在您提到的所有情况下,myrafaelpaper.js
的脚本标记都没有关闭(</script>
)。