我想从我的页面中的
HTML按钮调用paper.js函数,但我相信paper.js函数存在于它们自己的范围内. paper.js文档提到互操作性,这听起来像是正确的,然后带我到一个“即将推出”的页面:
http://paperjs.org/tutorials/getting-started/paperscript-interoperability/
解决方法
对于那个缺少教程的道歉.我真的会投入一些时间来写它.
我去年在邮件列表上回答了这个问题:https://groups.google.com/d/msg/paperjs/C6F0XFlplqM/_67AMqCR_nAJ
Scoped PaperScript run inside the global scope,and have access to all elements of the global scope. The normal JavaScripts running in the global scope (= window) will not see these PaperScopes,and won’t have access to their variables.
There is a simple solution to exchange information between the two: Simply declare a global structure that you use to exchange tings back and forth,e.g.
window.globals = { someValue: 10,someFunction: function() { alert(globals.someValue); } };
In your PaperScript,you can then access this simply through ‘globals’,since it’s in the window scope:
globals.someValue = 20; globals.someFunction();
同样,您可以使用普通JavaScript中的此结构.