简体   繁体   中英

Perfectly scroll to top. but when i scroll down and click anywhere on page, again scroll moves to the top

Here is my code. Works fine when renders the page but changes to top when i click down somwhere

   ngAfterViewChecked() {
      // this.mainPageComponent.rightPanel.nativeElement.scrollTo(0, 0);
      this.element.nativeElement.scrollIntoView();
   }

ngAfterViewChecked is triggered every time after angular has check the view of your component.

You should use ngOnInit if you want this effect to be trigger only at initialisation.

cf : https://angular.io/guide/lifecycle-hooks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM