Created
September 9, 2019 06:02
-
-
Save xx4159/12277c7ca840b6a326e399f689f2d716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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