Fixed auto scroll
This commit is contained in:
parent
11729f0281
commit
eb02a6302a
@ -23,11 +23,9 @@ export class NavbarComponent implements AfterViewInit, OnDestroy {
|
|||||||
constructor(private route: ActivatedRoute, private router: Router) { }
|
constructor(private route: ActivatedRoute, private router: Router) { }
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
|
||||||
this.sub = combineLatest([this.router.events.pipe(filter(e => e instanceof NavigationEnd)), this.route.fragment]).subscribe(([url, frag]) => {
|
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);
|
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'});
|
if(el) el.scrollIntoView({behavior: 'smooth'});
|
||||||
else setTimeout(() => this.scroll(id), 500);
|
else setTimeout(() => this.scroll(id), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scrollTop() {
|
||||||
|
const container = document.getElementsByClassName('app-container')[0];
|
||||||
|
container.scrollTo(0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user