import { Injectable } from '@angular/core' ; import { dom } from 'ngx-tethys/util' ; export class ScrollToService { static _customScrollToElement ( targetElement , containerElement ) { const containerOffset = dom . getElementOffset ( containerElement ) ; const targetOffset = dom . getElementOffset ( targetElement ) ; const topOffset = containerOffset . top - targetOffset . top ; const bottomOffset = targetOffset . top + targetOffset . height - ( containerOffset . top + containerOffset . height ) ; const viewOffset = targetOffset . height ; if ( topOffset > 0 ) { containerElement . scrollTop = containerElement . scrollTop - topOffset - viewOffset ; } else if ( bottomOffset > 0 ) { containerElement . scrollTop = containerElement . scrollTop + bottomOffset + viewOffset ; } } static scrollToElement ( targetElement , containerElement ) { if ( targetElement ) { this . _customScrollToElement ( targetElement , containerElement ) ; } } }