简体   繁体   English

完美滚动到顶部。 但是当我向下滚动并单击页面上的任意位置时,滚动再次移至顶部

[英]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. 每次在angular检查组件视图后都会触发ngAfterViewChecked。

You should use ngOnInit if you want this effect to be trigger only at initialisation. 如果希望仅在初始化时触发此效果,则应使用ngOnInit。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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