File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
core/pfe-core/controllers Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ export interface ScrollSpyControllerOptions extends IntersectionObserverInit {
2323 * @default el => el.getAttribute('href');
2424 */
2525 getHash ?: ( el : Element ) => string | null ;
26+ /**
27+ * Optional callback for when an intersection occurs
28+ */
29+ onIntersection ?( ) : void ;
2630}
2731
2832export class ScrollSpyController implements ReactiveController {
@@ -47,6 +51,7 @@ export class ScrollSpyController implements ReactiveController {
4751
4852 #getRootNode: ( ) => Node ;
4953 #getHash: ( el : Element ) => string | null ;
54+ #onIntersection?: ( ) => void ;
5055
5156 get #linkChildren( ) : Element [ ] {
5257 return Array . from ( this . host . querySelectorAll ( this . #tagNames. join ( ',' ) ) )
@@ -95,6 +100,7 @@ export class ScrollSpyController implements ReactiveController {
95100 this . #threshold = options . threshold ?? 0.85 ;
96101 this . #getRootNode = ( ) => options . rootNode ?? host . getRootNode ( ) ;
97102 this . #getHash = options ?. getHash ?? ( ( el : Element ) => el . getAttribute ( 'href' ) ) ;
103+ this . #onIntersection = options ?. onIntersection ;
98104 }
99105
100106 hostConnected ( ) : void {
@@ -172,6 +178,7 @@ export class ScrollSpyController implements ReactiveController {
172178 }
173179 this . #initializing = false ;
174180 }
181+ this . #onIntersection?.( ) ;
175182 }
176183
177184 /**
You can’t perform that action at this time.
0 commit comments