问题
I'm trying to learn paper.js from tutorials, but i'cant make it work from external file .What is the easiest way to implement external paperscript files?
回答1:
Like stated in the Getting started tutorial, if you want to use Paperjs with an external file:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/paper.js"></script>
<script type="text/paperscript" src="js/myScript.js" canvas="myCanvas"></script>
</head>
<body>
<canvas id="myCanvas" resize></canvas>
</body>
</html>
Be sure to specify:
- the script type "text/paperscript"
- your canvas ID with the attribute "canvas"
回答2:
--What about the new versions now? I still have the issue and Paperjs is at version 0.11.5?--
Actually I found the solution via another student in Udemy -Git link here. Go to the paper-full.js (it works only with the downloaded version, not CDN) and transform the line
xhr.open((options.method || 'get').toUpperCase(), options.url,
Base.pick(options.async, true));
into only
xhr.open((options.method || 'get').toUpperCase(), options.url);
I understood that's not to be used in normal website as it's against a security protocols, so it's just for practicing. The async method is optional according to Paperjs. By the way, for me it works on Firefox, but not in Chrome.
来源:https://stackoverflow.com/questions/19726895/how-to-use-paperscript-from-external-source