File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
core/pfe-core/controllers Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,18 @@ export interface ScrollSpyControllerOptions extends IntersectionObserverInit {
3030}
3131
3232export class ScrollSpyController implements ReactiveController {
33+ static #instances = new Set < ScrollSpyController > ;
34+
35+ static {
36+ addEventListener ( 'scroll' , ( ) => {
37+ if ( Math . round ( window . innerHeight + window . scrollY ) >= document . body . scrollHeight ) {
38+ this . #instances. forEach ( ssc => {
39+ ssc . #setActive( ssc . #linkChildren. at ( - 1 ) ) ;
40+ } ) ;
41+ }
42+ } , { passive : true } ) ;
43+ }
44+
3345 #tagNames: string [ ] ;
3446 #activeAttribute: string ;
3547
@@ -104,9 +116,15 @@ export class ScrollSpyController implements ReactiveController {
104116 }
105117
106118 hostConnected ( ) : void {
119+ ScrollSpyController . #instances. add ( this ) ;
107120 this . #initIo( ) ;
108121 }
109122
123+ hostDisconnected ( ) : void {
124+ ScrollSpyController . #instances. delete ( this ) ;
125+ this . #io?. disconnect ( ) ;
126+ }
127+
110128 #initializing = true ;
111129
112130 async #initIo( ) {
You can’t perform that action at this time.
0 commit comments