在JavaScript上调用模块中的呼叫功能?
我正在启动一个使用三库库的项目,我还将使用视差库。 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了将代码转换为常规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