Files
legio-30/src/app/directives/in-view.directive.ts
ztimson 16ddd1c8a3
All checks were successful
Build Website / Build NPM Project (push) Successful in 1m42s
Build Website / Tag Version (push) Successful in 1m2s
Build Website / Build Container (push) Successful in 2m50s
Updated site to use momentum for contacting, registration, gallery and calendar, as well as some other updates to the site content
2026-06-05 19:19:27 -04:00

25 lines
618 B
TypeScript

import {Directive, ElementRef, EventEmitter, OnDestroy, OnInit, Output} from '@angular/core';
@Directive({selector: '[inView]'})
export class InViewDirective implements OnInit, OnDestroy {
@Output() inView = new EventEmitter<void>();
private observer!: IntersectionObserver;
constructor(private el: ElementRef) {}
ngOnInit() {
this.observer = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
this.inView.emit();
this.observer.disconnect();
}
}, {rootMargin: '200px'});
this.observer.observe(this.el.nativeElement);
}
ngOnDestroy() {
this.observer.disconnect();
}
}