@@ -25,6 +25,7 @@ class ScrollMonitor {
2525 onEnterViewport ?: ( ) => any ,
2626 onFullyEnterViewport ?: ( ) => any ,
2727 onExitViewport ?: ( ) => any ,
28+ enableByScroll ?: boolean ,
2829 ) => {
2930 ScrollMonitor . monitorScroll ( ) ;
3031
@@ -51,6 +52,8 @@ class ScrollMonitor {
5152 offset,
5253 inView : false ,
5354 fullyInView : false ,
55+ enableByScroll,
56+ hasViewBeenScrolled : false ,
5457 onEnterViewport : onEnterViewport ? [ onEnterViewport ] : [ ] ,
5558 onFullyEnterViewport : onFullyEnterViewport ? [ onFullyEnterViewport ] : [ ] ,
5659 onExitViewport : onExitViewport ? [ onExitViewport ] : [ ] ,
@@ -80,12 +83,17 @@ class ScrollMonitor {
8083 const windowHeight = window . innerHeight ;
8184
8285 Object . entries ( ScrollMonitor . registeredAds ) . forEach ( ( [ key , ad ] ) => {
86+ ad . hasViewBeenScrolled = true ;
8387 ScrollMonitor . evaulateCurrentViewability ( ad , windowHeight ) ;
8488 } ) ;
8589
8690 } , ScrollMonitor . throttleDuration )
8791
8892 private static evaulateCurrentViewability = ( ad : IScrollMonitorRegisteredAd , windowHeight : number ) => {
93+ if ( ad . enableByScroll && ! ad . hasViewBeenScrolled ) {
94+ return ;
95+ }
96+
8997 const bounding = ad . element . getBoundingClientRect ( ) ;
9098
9199 const inView = ( bounding . top - ad . offset ) <= windowHeight && ( bounding . top + bounding . height ) >= 0 ;
0 commit comments