簡體   English   中英

完美滾動到頂部。 但是當我向下滾動並單擊頁面上的任意位置時,滾動再次移至頂部

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

這是我的代碼。 呈現頁面時效果很好,但是當我在某處單擊時會變為頂部

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

每次在angular檢查組件視圖后都會觸發ngAfterViewChecked。

如果希望僅在初始化時觸發此效果,則應使用ngOnInit。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM