Angular Scroll Spy не работает с IE11? - PullRequest
0 голосов
/ 13 июня 2019

Я сделал директиву Angular Scroll Spy, которая отлично работает в Chrome, но не работает ожидаемо в IE11

Я пытаюсь реализовать функцию прокрутки шпиона в приложении Angular 6.

Я пытался добиться этого с помощью угловой директивы, которая прекрасно работает в Chrome, но демонстрирует странное поведение с IE11.

@Directive({
    selector: '[scrollSpy]'
})
export class ScrollSpyDirective {
    @Input() public spiedTags = [];
    @Output() public sectionChange = new EventEmitter<string>();
    private currentSection: string ='';

    constructor(private _el: ElementRef) {}

    @HostListener('scroll', ['$event'])
    onScroll(event: any) {
        let currentSection1: string='';
        const children = this._el.nativeElement.children;
        const scrollTop = event.target.scrollTop;
        const parentOffset = event.target.offsetTop;
        for (let i = 0; i < children.length; i++) {
            const element = children[i];
            if (this.spiedTags.some(spiedTag => spiedTag === element.tagName)) {
                if ((element.offsetTop - parentOffset) <= scrollTop) {
                    currentSection1 = element.id;
                }
            }
        }
        if (currentSection1 !== this.currentSection) {
            this.currentSection = currentSection1;
            this.sectionChange.emit(this.currentSection);
        }
    }

}

Это прекрасно работает с Chrome, но не работает должным образом в IE11.

...