Ionic Angular Scroll Top

agnusdei·2023년 7월 5일
0
<main
  #container
  class="flex w-screen h-screen overflow-x-hidden overflow-y-auto"
>
	<router-outlet (activate)="onActivate($event)"></router-outlet>
</main>
  1. activate

이벤트를 달아줍니다. 페이지가 이동할 때 마다 activate 되겠죠?

  1. ViewChild 로 핸들링 하기 위해 #container
@ViewChild('container') containerRef!: ElementRef<HTMLElement>;


onActivate(e: any) {
    this.containerRef.nativeElement.scrollTo({ top: 0, behavior: 'smooth' });
  }
  1. scrollTo 메소드를 활영하여 해당 좌표로 이동합니다. top:0

  2. behavior 옵션을 활용하여 smooth 하게 이동합니다.

0개의 댓글