如何在一个html中组合rafael.js和paper.js?

时间:2015-07-15 14:51:45

标签: javascript paperjs rafaeljs

当我试图在一个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. paper.js输出:未捕获错误:无法找到id为#34; myCanvas&#34;的画布,但画布就在那里。这是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文件(&#34; myrafaelpaper.js&#34;)中使用rafael和纸质代码时,同样的错误也发生了,尽管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>

另外,它们工作正常。

&#34; myrafaelpaper.js&#34;在这里:

//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;

&#34; myrafael.js&#34;的内容和#34; mypaper.js&#34;是类比的。

1 个答案:

答案 0 :(得分:1)

在您提到的所有案例中,myrafaelpaper.js的脚本标记未关闭(</script>)。