From eb02a6302af421de86d8ac5e0cb6fa9663e462b3 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sun, 30 Oct 2022 08:23:36 -0400 Subject: [PATCH] Fixed auto scroll --- src/app/components/navbar/navbar.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/components/navbar/navbar.component.ts b/src/app/components/navbar/navbar.component.ts index e9b66cc..36a8a7d 100644 --- a/src/app/components/navbar/navbar.component.ts +++ b/src/app/components/navbar/navbar.component.ts @@ -23,11 +23,9 @@ export class NavbarComponent implements AfterViewInit, OnDestroy { constructor(private route: ActivatedRoute, private router: Router) { } ngAfterViewInit() { - this.sub = combineLatest([this.router.events.pipe(filter(e => e instanceof NavigationEnd)), this.route.fragment]).subscribe(([url, frag]) => { - console.log('fire', frag); if(frag) this.scroll(frag); - else this.scroll('top'); + else this.scrollTop(); }); } @@ -40,4 +38,9 @@ export class NavbarComponent implements AfterViewInit, OnDestroy { if(el) el.scrollIntoView({behavior: 'smooth'}); else setTimeout(() => this.scroll(id), 500); } + + scrollTop() { + const container = document.getElementsByClassName('app-container')[0]; + container.scrollTo(0, 0); + } }