File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed
Examples/Applications/OfflineLocalView Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff 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+
3661export 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
You can’t perform that action at this time.
0 commit comments