Slider container: Fix error about observer

This commit is contained in:
Konstantinos Triantafyllou 2023-10-16 14:34:48 +03:00
parent 5948d61a47
commit 8d6522270c
1 changed files with 21 additions and 19 deletions

View File

@ -60,7 +60,7 @@ export class SliderContainerComponent implements OnInit, OnDestroy, AfterContent
}
ngOnDestroy() {
if(this.observer) {
if(this.observer && typeof IntersectionObserver !== 'undefined') {
this.observer.disconnect();
}
}
@ -78,24 +78,26 @@ export class SliderContainerComponent implements OnInit, OnDestroy, AfterContent
}
setObserver() {
let options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
this.observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting && !this.initialized) {
this.stopped = false;
this.start(0);
this.initialized = true;
} else {
this.initialized = false;
this.stopped = true;
}
});
}, options);
this.observer.observe(this.element.nativeElement);
if(typeof IntersectionObserver !== 'undefined') {
let options = {
root: null,
rootMargin: '0px',
threshold: 0.1
};
this.observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting && !this.initialized) {
this.stopped = false;
this.start(0);
this.initialized = true;
} else {
this.initialized = false;
this.stopped = true;
}
});
}, options);
this.observer.observe(this.element.nativeElement);
}
}
start(time: number) {