@@ -137,6 +137,16 @@ function getDocumentHeight() {
137137}
138138
139139function getCurrentScrollDepthPx ( ) {
140+ if ( COMPILE_COMPAT ) {
141+ var el = document . documentElement || { }
142+ var body = document . body || { }
143+ var viewportHeight = window . innerHeight || el . clientHeight || 0
144+ var scrollTop = window . scrollY || window . pageYOffset || el . scrollTop || body . scrollTop || 0
145+ return currentDocumentHeight <= viewportHeight
146+ ? currentDocumentHeight
147+ : scrollTop + viewportHeight
148+ }
149+
140150 var viewportHeight = window . innerHeight
141151 var scrollTop = window . scrollY
142152
@@ -149,9 +159,20 @@ export function init() {
149159 currentDocumentHeight = getDocumentHeight ( )
150160 maxScrollDepthPx = getCurrentScrollDepthPx ( )
151161
152- new ResizeObserver ( function ( ) {
153- currentDocumentHeight = getDocumentHeight ( )
154- } ) . observe ( document . documentElement )
162+ if ( COMPILE_COMPAT ) {
163+ window . addEventListener ( 'load' , function ( ) {
164+ currentDocumentHeight = getDocumentHeight ( )
165+ var count = 0
166+ var interval = setInterval ( function ( ) {
167+ currentDocumentHeight = getDocumentHeight ( )
168+ if ( ++ count === 15 ) clearInterval ( interval )
169+ } , 200 )
170+ } )
171+ } else {
172+ new ResizeObserver ( function ( ) {
173+ currentDocumentHeight = getDocumentHeight ( )
174+ } ) . observe ( document . documentElement )
175+ }
155176
156177 document . addEventListener ( 'scroll' , function ( ) {
157178 var currentScrollDepthPx = getCurrentScrollDepthPx ( )
0 commit comments