在Angular 7应用程序中使用Intersection Observer在IE11中冻结的解决方法是使用polyfill来模拟Intersection Observer的功能。下面是一个解决方案的代码示例:
npm install intersection-observer
import 'intersection-observer';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
@Component({
selector: 'app-my-component',
template: 'My Component'
})
export class MyComponent implements OnInit {
@ViewChild('elementRef') elementRef: ElementRef;
ngOnInit() {
const options = {
root: null,
rootMargin: '0px',
threshold: 1.0
};
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
console.log('Element is intersecting');
// Do something when element is intersecting
} else {
console.log('Element is not intersecting');
// Do something when element is not intersecting
}
});
}, options);
observer.observe(this.elementRef.nativeElement);
}
}
通过使用Intersection Observer的polyfill,你的Angular 7应用程序中的Intersection Observer在IE11中应该能正常工作。