在JavaScript上调用模块中的呼叫功能?

发布于 2025-01-25 18:15:47 字数 1615 浏览 1 评论 0 原文

我正在启动一个使用三库库的项目,我还将使用视差库。 3D效果仅是装饰性的,但是视差会触发它。

我修改了这个示例,对我来说很好: 演示: https://threejs.org/threejs.s.org/examples/#webgl_geometry_geometry_text_text_shapes_shapes 代码:

...但是我需要将每个部分的标题(当用户向下滚动滚动时输入它)的标题发送到3D脚本代码,并且它在内部关闭,并且它在内部关闭一个模块。

...怎么做?我是三个.js和模块的新手,并希望保持视差原样(外部模块,因为它是一个众所周知的库,并且是开发项目的一部分)

,也许正确的方法是在没有模块的情况下转换示例代码。 ..但是我迷失了方向...例如,模块中JS的起始部分是:

import * as THREE from 'three';

import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { SVGLoader } from './jsm/loaders/SVGLoader.js';
import { FontLoader } from './jsm/loaders/FontLoader.js';

...如果没有模块 /导入,该怎么做?

预先感谢

==============================

我添加了一个示例(最大简化)而无效):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>three.js webgl - simple text from json</title>
    </head>
    <body>
        <script type="module">
            init();
            function init() {
                function hi( text) {
                    alert(text);
                }
            } // end init
        </script>
        <script>
            init().hi("hi world");
        </script>
    </body>
</html>

I'm starting a project that uses three.js library, and I will use also a parallax library. The 3D effects will be only decorative, but parallax will trigger it.

I modified this example and works fine for me:
demo: https://threejs.org/examples/#webgl_geometry_text_shapes
code: https://github.com/mrdoob/three.js/blob/master/examples/webgl_geometry_text_shapes.html

...but I need to send the title of every section (when the user enter on it by scrolling down) to the 3D script code, and it is closed inside a module.

...How to to it? I'm newbie into three.js and modules, and want to keep the parallax as is (outside module, because it's a well-known library and part of developed yet project)

Maybe the right way is transform the sample code, without modules... but I'm lost with it... for example, the starting part of JS in module, are:

import * as THREE from 'three';

import { OrbitControls } from './jsm/controls/OrbitControls.js';
import { SVGLoader } from './jsm/loaders/SVGLoader.js';
import { FontLoader } from './jsm/loaders/FontLoader.js';

...how to do it without modules / import?

Thanks in advance

==================================

I add an example (maximum simplified) about what I need (and not works):

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>three.js webgl - simple text from json</title>
    </head>
    <body>
        <script type="module">
            init();
            function init() {
                function hi( text) {
                    alert(text);
                }
            } // end init
        </script>
        <script>
            init().hi("hi world");
        </script>
    </body>
</html>

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

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

发布评论

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

评论(1

撩动你心 2025-02-01 18:15:47

我解决了将代码转换为常规JS,而不是模块JS。

在库三。js中,每个控件都有一个用于模块的版本(in /jsm文件夹)和普通的JS版本( /js文件夹)。

还更改了三个.js文件的主文件三。module.js。

谢谢

I solved this turning the code into regular JS, not module JS.

In the library three.js, there is for each control a version for module (into /jsm folder) and normal JS version (/js folder).

Also changed the main file three.module.js for three.js file.

Thank you

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