Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created June 10, 2019 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NetanelBasal/bb7a9320d6d356fb4ea81709224256b4 to your computer and use it in GitHub Desktop.
Save NetanelBasal/bb7a9320d6d356fb4ea81709224256b4 to your computer and use it in GitHub Desktop.
@Component({
selector: 'infinite-scroll',
template: `<ng-content></ng-content><div #anchor></div>`
})
export class InfiniteScrollComponent implements OnInit, OnDestroy {
...
ngOnInit() {
const options = {
root: this.isHostScrollable() ? this.host.nativeElement : null,
...this.options
};
this.observer = new IntersectionObserver(([entry]) => {
entry.isIntersecting && this.scrolled.emit();
}, options);
this.observer.observe(this.anchor.nativeElement);
}
private isHostScrollable() {
const style = window.getComputedStyle(this.element);
return style.getPropertyValue('overflow') === 'auto' ||
style.getPropertyValue('overflow-y') === 'scroll';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment