Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import { Injectable } from '@angular/core';
import 'intersection-observer';
declare global {
interface Window {
IntersectionObserver: IntersectionObserver;
}
}
const defaults = {
root: null,
rootMargin: '0px 0px 0px 0px',
threshold: [0, 0.25, 0.5, 0.75, 1],
};
@Injectable()
export class IntersectionObserverService {
observer: IntersectionObserver;
constructor(
callback: IntersectionObserverCallback,
options: IntersectionObserverInit = defaults
) {
if (window.IntersectionObserver) {
this.observer = new IntersectionObserver(callback, options);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.