fix: perfect scrollbar not scrolling to top after changing page
This commit is contained in:
1 parent
6c30218a51
commit
c9c7a92012
1 file changed
+17
-1
@@ -1,4 +1,7 @@
|
||||
import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { filter } from 'rxjs';
|
||||
|
||||
import PerfectScrollbar from 'perfect-scrollbar';
|
||||
|
||||
@Component({
|
||||
@@ -7,12 +10,25 @@ import PerfectScrollbar from 'perfect-scrollbar';
|
||||
styleUrl: './app.component.css',
|
||||
})
|
||||
export class AppComponent implements AfterViewInit {
|
||||
title = 'ShowZ';
|
||||
|
||||
@ViewChild('scrollContainer', { static: true }) scrollContainer!: ElementRef;
|
||||
private ps!: PerfectScrollbar;
|
||||
|
||||
title = 'ShowZ';
|
||||
constructor(private router: Router) {}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.ps = new PerfectScrollbar(this.scrollContainer.nativeElement);
|
||||
|
||||
this.router.events
|
||||
.pipe(filter(event => event instanceof NavigationEnd))
|
||||
.subscribe(() => {
|
||||
this.scrollToTop();
|
||||
});
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
this.scrollContainer.nativeElement.scrollTop = 0;
|
||||
this.ps.update();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user