Angular CLI: 17.1.0
Node: 18.16.0
Package Manager: npm 9.5.1
OS: linux x64
(Tailwind 사용)
문제: scroll 이벤트를 감지를 못 해서 계속 console이 찍히지 않음
windowScrolled = false;
ngOnInit() {
window.addEventListener('scroll', (event) => {
console.log('스크롤 이벤트 발생');
this.windowScrolled = window.scrollY !== 0;
});
}
scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth',
});
}
문제 원인: sidenav의 h-screen
h-screen을 지워주니까 scroll event도 감지하고 window.scrollTo 도 잘 먹었다.
아래 코드를 보면 sidenav에 h-screen이 존재
<div class="bg-[#F8F7FC]">
<mat-sidenav-container
(backdropClick)="closeEvent()"
class="h-screen bg-[#F8F7FC]"
>
<mat-sidenav #sidenav autoFocus="false" [mode]="'over'">
<sidenav></sidenav>
</mat-sidenav>
<mat-sidenav-content class="flex flex-col">
<app-toolbar></app-toolbar>
<!-- class="main_area" -->
<main class="pt-20 bg-[#F8F7FC] h-full w-[1440px] mx-auto px-8">
<router-outlet></router-outlet>
</main>
</mat-sidenav-content>
</mat-sidenav-container>
</div>
'Publishing' 카테고리의 다른 글
count up_jquery (0) | 2023.03.14 |
---|---|
gnb (0) | 2023.03.08 |
풀페이지 (0) | 2023.03.08 |
풀페이지 (0) | 2023.03.08 |
Splitting (0) | 2023.03.02 |