Skip to content

Commit c55057d

Browse files
Merge branch 'master' of https://github.com/rodrigobasilio2022/vtk-js into feat/VolumePicker
2 parents 4766908 + cb9f5ae commit c55057d

File tree

1 file changed

+28
-1
lines changed
  • Examples/Applications/OfflineLocalView

1 file changed

+28
-1
lines changed

Examples/Applications/OfflineLocalView/index.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ function preventDefaults(e) {
3333
e.stopPropagation();
3434
}
3535

36+
function onVisible(element, callback) {
37+
new window.parent.IntersectionObserver((entries, observer) => {
38+
entries.forEach((entry) => {
39+
if (entry.intersectionRatio > 0) {
40+
callback();
41+
observer.disconnect();
42+
}
43+
});
44+
}).observe(element);
45+
}
46+
47+
function runOnVisible(callback) {
48+
if (!window.frameElement) {
49+
callback();
50+
return true;
51+
}
52+
const visible = window.frameElement.getClientRects().length > 0;
53+
if (!visible) {
54+
onVisible(window.frameElement, callback);
55+
} else {
56+
callback();
57+
}
58+
return visible;
59+
}
60+
3661
export function load(container, options) {
3762
autoInit = false;
3863
emptyContainer(container);
@@ -161,7 +186,9 @@ if (userParams.url || userParams.fileURL) {
161186
rootBody.style.margin = '0';
162187
rootBody.style.padding = '0';
163188
}
164-
load(myContainer, userParams);
189+
190+
autoInit = false;
191+
runOnVisible(() => load(myContainer, userParams));
165192
}
166193

167194
// Auto setup if no method get called within 100ms

0 commit comments

Comments
 (0)