javascript - 重新加载 DOM 元素而不重新加载整个页面(修改源 html)
问题描述
假设我有一个WebGL
应用程序,并且在 HTML 文档中内联着色器,我想要的是更改 HTML 文档并重新加载着色器而不重新加载整个站点,我使用 iframe 进行了修复,但这是可能的最糟糕的解决方案因为WebGL
应用程序(以及他所有的回调)运行了两次,有没有更好的解决方案来解决这个问题?
let frame = document.getElementById("iframe");
// Reload the shaders when R is pressed
window.addEventListener("keypress", e => {
if (e.code === "KeyR") {
// Reload the html document of the iframe
frame.contentDocument.location.reload(true);
// Get the sources from the iframe and reload the shaders
reloadShaders();
}
});
我不希望重新加载整个页面以不丢失我正在做的事情的状态,只需实时更改着色器,我也不希望使用专门用于此任务的服务器,在此先感谢。
内联着色器示例
<script type="glsl" id="basic.vs">#version 300 es
void main() {
gl_Position = vec4(
2 * (gl_VertexID / 2) - 1,
2 * (gl_VertexID % 2) - 1,
0.0, 1.0
);
}
</script>
解决方案
推荐阅读
- mysql - 提取具有特定模式的子字符串
- google-analytics - 如何让 GTM 的内置 YouTube 触发器触发通过 JS 单击功能创建的模态播放的视频
- xslt - 如何将增量 id 连接到现有值
- parceljs - 使用 Parcel 删除 console.logs?
- c++ - 如何在 Wait() C++ 期间同时调用另一个函数
- postgresql - 无法通过 -v 共享 docker 容器数据
- apache - WampServer : 使用 VPN 访问目录
- typescript - TypeError:参数必须是字符串,而不是对象
- python - 保存 tensorflow 编码器、解码器和注意力
- c# - 存储用于 SharePoint 文件下载的凭证 c#