import { Injectable } from '@angular/core'; import {DocumentService} from './document.service'; function getWindow(): Window { return window; } @Injectable({ providedIn: 'root' }) export class WindowService { constructor(private documentService: DocumentService) { } public nativeWindow(): Window | any { return getWindow(); } public getXYScroll(): {x: number, y: number } { const supportPageOffset = this.nativeWindow().pageXOffset !== undefined; const isCSS1Compat = ((this.documentService.nativeDocument().compatMode || '') === 'CSS1Compat'); const x = supportPageOffset ? this.nativeWindow().pageXOffset : isCSS1Compat ? this.documentService.nativeDocument().documentElement.scrollLeft : this.documentService.nativeDocument().body.scrollLeft; const y = supportPageOffset ? this.nativeWindow().pageYOffset : isCSS1Compat ? this.documentService.nativeDocument().documentElement.scrollTop : this.documentService.nativeDocument().body.scrollTop; return {x, y}; } }