简体   繁体   English

Autodesk Forge Viewer的多个实例

[英]Multiple instances of Autodesk Forge Viewer

I'm trying to have multiple instances of the Autodesk Forge Viewer (v6.2) running on my page, but hidden in tabs. 我试图在我的页面上运行多个Autodesk Forge Viewer(v6.2)实例,但隐藏在选项卡中。

As the user switches tabs it will hide and show the viewer with a loaded model. 当用户切换选项卡时,它将隐藏并显示带有已加载模型的查看器。

While I have this working, any hidden instances that have loaded a model break on events (Eg resize event), giving an error like: 在执行此操作的同时,任何已加载模型的隐藏实例都会在事件(例如resize事件)上中断,并给出如下错误:

VM19014 viewer3D.min.js:53 Uncaught TypeError: Cannot read property '__webglFramebuffer' of null
    at k.initFrameBufferMRT (VM19014 viewer3D.min.js:53)

I have looked at .tearDown() and finish() but they seem to completely unload the model in the viewer, slowing the experience for the user. 我已经看过.tearDown()finish()但是它们似乎完全在查看器中卸载了模型,从而降低了用户的体验。

Is there a way to pause the viewer if it's not visible? 如果看不见,是否可以暂停查看器?

Edit: 编辑:

I've accepted the answer below as it is a correct solution and probably one I would go for if I was re-doing the page. 我接受了以下答案,因为它是一种正确的解决方案,而且如果我要重新制作此页面,可能是一个正确的解决方案。

In the end, I went for a different workaround where I moved the entire tab content offscreen so the canvas is still live in the DOM and it doesn't jump my content around: 最后,我采用了另一种解决方法,将整个选项卡的内容移到了屏幕外,因此画布仍位于DOM中,并且不会跳动我的内容:

  .tab-content {
    top: -9999px;
    left: -9999px;
    position: absolute;
    display: block !important;
  }

I'm afraid there's no way to suspend the initialization of the viewer. 恐怕没有办法暂停查看器的初始化。 It can only be initialized with non-zero-size canvas. 只能使用非零尺寸的画布进行初始化。 You could try hiding the multiple instances of the viewer using z-index instead of display:none so that they all get a non-empty canvas and are initialized properly. 您可以尝试使用z-index而不是display:none隐藏查看器的多个实例,以使它们都获得非空画布并正确初始化。

Besides z-index setting visibility to hidden also works well: 除了z-index设置, hidden visibility也很有效:

#MyViewerDiv {visibility: hidden;}

Working code: https://jsfiddle.net/dukedhx/bp9dycrt/ 工作代码: https//jsfiddle.net/dukedhx/bp9dycrt/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM