gpt4 book ai didi

javascript - Paper.js 互操作性

转载 作者:太空狗 更新时间:2023-10-29 14:14:42 25 4
gpt4 key购买 nike

我想从页面中的 HTML 按钮调用 paper.js 函数,但我相信 paper.js 函数存在于它们自己的范围内。 paper.js 文档提到了互操作性,这听起来很正确,然后直接将我带到一个页面,上面写着“即将推出”:

http://paperjs.org/tutorials/getting-started/paperscript-interoperability/

有谁知道如何从我的 HTML 页面调用在 paper.js 脚本中创建的函数?

最佳答案

对于缺少的教程深表歉意。我真的会花一些时间来写它。

我去年在邮件列表中回答了这个问题: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 中使用此结构。

关于javascript - Paper.js 互操作性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com