外部 paperscript 文件根本没有加载到我的 html 文件中

发布于 2025-01-20 08:40:15 字数 1179 浏览 2 评论 0原文

我正在尝试为 paper.js 制作一个基本测试程序,我打算将其用于项目。 我正在使用 chrome 来运行 HTML,当我打开开发工具时,chrome 似乎根本不加载我的脚本之一。我的文件结构是:

Test
|---mario.svg
|---html.html
|---scripts/
|   |---script.js
|   |---paper-core.js

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="./scripts/paper-full.min.js"></script>
    <script type="text/paperscript" src="./scripts/script.js" canvas="myCanvas"></script>
</head>
<body>

<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #d3d3d3;">
</canvas>
</body>
</html>
veiw.onFrame = function(event){
    project.importSVG('.../mario.svg');
};

但是,在 chrome 开发工具中,在源代码下,我希望看到与我的文件结构相匹配的内容,而且我确实这样做了,只是缺少 script.js。 它还给了我这个错误: 从源“null”访问“file:///C:/Users/jacob/Documents/JS/Testing/scripts/script.js”处的 XMLHttpRequest 已被 CORS 策略阻止:仅协议方案支持跨源请求:http、数据、chrome、chrome-extension、chrome-untrusted、https。 ht @ paper-full.min.js:32

我认为这一定与文本/paperscript 有关,但我真的不知道,也绝对不知道如何解决它。我查看了示例,但无法弄清楚我在做什么不同的事情。 mario.svg 也没有显示,但我认为这只是因为 html 中没有引用它。有人可以解释一下吗?

I am trying to make a basic test program for paper.js, which I intend to use for a project.
I am using chrome to run the HTML and when I open the dev tools chrome seems to simply not load one of my scripts. My file structure is:

Test
|---mario.svg
|---html.html
|---scripts/
|   |---script.js
|   |---paper-core.js

And here is my code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="./scripts/paper-full.min.js"></script>
    <script type="text/paperscript" src="./scripts/script.js" canvas="myCanvas"></script>
</head>
<body>

<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #d3d3d3;">
</canvas>
</body>
</html>
veiw.onFrame = function(event){
    project.importSVG('.../mario.svg');
};

In the chrome dev tools however, under sources, I would expect to see something that matches my file structure, and I do, except script.js is missing.
Also it gives me this error:
Access to XMLHttpRequest at 'file:///C:/Users/jacob/Documents/JS/Testing/scripts/script.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.
ht @ paper-full.min.js:32

I think it must be something to do with the text/paperscript, but I really don't know and definately don't know how to fix it. I've looked at examples and can't figure out what I am doing differently. The mario.svg doesn't show up either but I think that's just because its not referenced in the html. Can someone explain this please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

窗影残 2025-01-27 08:40:15

乍一看,我会说你的 PaperScript 代码没有运行,因为你加载了错误版本的 Paper.js。
您正在加载 paper-core.js,这是不支持 PaperScript 的 Paper.js 版本。您应该改为加载 paper-full.js

At first sight, I would say that your PaperScript code is not run because you load the wrong version of Paper.js.
You are loading paper-core.js which is the version of Paper.js that does not support PaperScript. You should load paper-full.js instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文