Skip to content

Instantly share code, notes, and snippets.

@xx4159
Created September 9, 2019 06:02
Show Gist options
  • Save xx4159/12277c7ca840b6a326e399f689f2d716 to your computer and use it in GitHub Desktop.
Save xx4159/12277c7ca840b6a326e399f689f2d716 to your computer and use it in GitHub Desktop.
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