@@ -8,6 +8,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
8
8
"use strict" ;
9
9
const Globals = {
10
10
scroll : 0 ,
11
+ screenHeight : 0 ,
11
12
rafActive : true ,
12
13
rafId : 0 ,
13
14
renderedInitially : false ,
@@ -337,7 +338,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
337
338
this . start . updateLimits ( ) ;
338
339
this . end . updateLimits ( ) ;
339
340
if ( this . end . top < this . start . top )
340
- this . end . top += window . innerHeight ;
341
+ this . end . top += Globals . screenHeight ;
341
342
this . helper . updateLimits ( ) ;
342
343
for ( let property of this . properties ) {
343
344
property . updateLimits ( ) ;
@@ -404,9 +405,9 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
404
405
this . domElement = domElement ;
405
406
}
406
407
updateLimits ( ) {
407
- this . top = this . domElement . getBoundingClientRect ( ) . top + Globals . scroll ;
408
+ this . top = ~ ~ this . domElement . getBoundingClientRect ( ) . top + Globals . scroll ;
408
409
if ( this . edge === "bottom" )
409
- this . top -= window . innerHeight ;
410
+ this . top -= Globals . screenHeight ;
410
411
}
411
412
}
412
413
const _DriverHelper = class {
@@ -427,9 +428,9 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
427
428
let top = this . driver . start . top ;
428
429
let end = this . driver . end . top ;
429
430
if ( this . driver . start . edge === "bottom" )
430
- top += window . innerHeight ;
431
+ top += Globals . screenHeight ;
431
432
if ( this . driver . end . edge === "bottom" )
432
- end += window . innerHeight ;
433
+ end += Globals . screenHeight ;
433
434
this . domElement . style . setProperty ( "top" , top + "px" ) ;
434
435
this . domElement . style . setProperty ( "height" , end - top + "px" ) ;
435
436
}
@@ -478,7 +479,7 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
478
479
class TheSuperSonicPluginForScrollBasedAnimation2 {
479
480
constructor ( config ) {
480
481
__publicField ( this , "observer" , null ) ;
481
- __publicField ( this , "resizeWrapper " , null ) ;
482
+ __publicField ( this , "onResize " , null ) ;
482
483
var _a ;
483
484
Globals . initConfig ( config ) ;
484
485
this . initInstances ( ) ;
@@ -526,40 +527,47 @@ var TheSuperSonicPluginForScrollBasedAnimation = function() {
526
527
}
527
528
}
528
529
updateLimits ( ) {
530
+ this . updateScreenHeight ( ) ;
529
531
this . updateScroll ( ) ;
530
532
Driver . updateLimits ( ) ;
531
533
if ( Globals . config . hooks . onUpdateLimits )
532
534
Globals . config . hooks . onUpdateLimits ( ) ;
533
535
}
534
536
updateScroll ( ) {
535
- Globals . scroll = window . pageYOffset || window . scrollY || document . documentElement . scrollTop || document . body . scrollTop ;
537
+ Globals . scroll = window . scrollY || window . pageYOffset || document . documentElement . scrollTop || document . body . scrollTop ;
538
+ }
539
+ updateScreenHeight ( ) {
540
+ const styles = {
541
+ position : "absolute" ,
542
+ left : "0" ,
543
+ top : "0" ,
544
+ height : "100vh" ,
545
+ width : "1px" ,
546
+ zIndex : "-1" ,
547
+ visibility : "hidden"
548
+ } ;
549
+ let helper = document . createElement ( "div" ) ;
550
+ for ( let property in styles ) {
551
+ helper . style . setProperty ( property , styles [ property ] ) ;
552
+ }
553
+ document . body . appendChild ( helper ) ;
554
+ Globals . screenHeight = helper . clientHeight ;
555
+ helper . remove ( ) ;
536
556
}
537
557
addEventListeners ( ) {
538
- this . resizeWrapper = debounce ( ( ) => {
558
+ this . onResize = ( ) => {
539
559
this . updateLimits ( ) ;
540
560
this . render ( { useActiveDrivers : false } ) ;
541
- } ) ;
542
- window . addEventListener ( "resize" , this . onResize . bind ( this ) ) ;
561
+ } ;
562
+ window . addEventListener ( "resize" , this . onResize ) ;
543
563
}
544
564
removeEventListeners ( ) {
545
565
window . removeEventListener ( "resize" , this . onResize ) ;
546
566
}
547
- onResize ( ) {
548
- this . resizeWrapper ( ) ;
549
- }
550
567
}
551
568
__publicField ( TheSuperSonicPluginForScrollBasedAnimation2 , "Driver" , Driver ) ;
552
569
__publicField ( TheSuperSonicPluginForScrollBasedAnimation2 , "Property" , Property ) ;
553
570
__publicField ( TheSuperSonicPluginForScrollBasedAnimation2 , "Element" , Element ) ;
554
571
__publicField ( TheSuperSonicPluginForScrollBasedAnimation2 , "Globals" , Globals ) ;
555
- function debounce ( func ) {
556
- let timer ;
557
- return ( ) => {
558
- clearTimeout ( timer ) ;
559
- timer = setTimeout ( ( ) => {
560
- func . apply ( this ) ;
561
- } , 500 ) ;
562
- } ;
563
- }
564
572
return TheSuperSonicPluginForScrollBasedAnimation2 ;
565
573
} ( ) ;
0 commit comments