I'm trying to set two sticky divs (one header, one sidenav) using Angular Material. Sticky divs works except from scrolling event when I scroll down into my content.
And when I scroll down, I have something like this :
My problem is : When I scroll down, I haven't any scroll event from Angular. If I change style.scss file by setting a value to height css property, all sticky div doesn't work anymore BUT I have my scroll event from Angular.
It's getting to my nerve :( Any idea to solve this problem ? Thank you very much !
style.scss
html, body {
min-height: auto; // sticky header doesn't work but scroll event Angular OK
// height: 100%; // sticky header works but scroll event Angular NOK
}
body {
margin: 0;
font-family: Roboto, "Helvetica Neue", sans-serif;
}
STICKY HEADER CODE :
app.component.html
<div class="app-wrapper">
<router-outlet></router-outlet>
</div>
.app-wrapper {
min-height: 100%;
overflow-x: hidden;
}
.my-toolbar {
position: sticky;
position: -webkit-sticky; /* For macOS/iOS Safari */
top: 0; /* Sets the sticky toolbar to be on top */
}
app-main.component.html
<mat-toolbar color="primary" class="my-toolbar">
<mat-toolbar-row>
<div fxFlex fxLayoutAlign="flex-start">
<mat-icon routerLink="/home">home</mat-icon>
</div>
<h1>My title</h1>
</mat-toolbar-row>
</mat-toolbar>
<router-outlet></router-outlet>
app-main.scss
.app-toolbar {
position: sticky;
position: -webkit-sticky; /* For macOS/iOS Safari */
top: 0; /* Sets the sticky toolbar to be on top */
}
STICKY MENU
app-content.html
<div fxLayout="column">
<img fxFlex="10" src="assets/test.jpg" alt="menu picture" />
<div class="categories nav-menu color-primary">
<app-horizontal-nav
[navItems]="categories$ | async">
</app-horizontal-nav>
</div>
<!-- content -->
<app-products></app-products>
</div>
app-content.scss
.nav-menu {
position: sticky;
position: -webkit-sticky; /* For macOS/iOS Safari */
top: 50px; // for the first sticky header
}
EDIT :
Here a stackblitz demo : https://stackblitz.com/edit/angular-9-0-0-rc-1-zhoy51 in style.scss, change height from auto to 100% and sticky headers will works. BUT none scroll event from scrolledToDirective are fired.