How to use paperscript from external source?

牧云@^-^@ 提交于 2019-12-10 15:38:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!