Hides menu after a delay. Shows menu while scrolling.
This commit is contained in:
parent
5fc0a0422e
commit
2bc564d4fc
|
@ -7,7 +7,8 @@
|
||||||
fxLayout="column"
|
fxLayout="column"
|
||||||
fxLayoutGap="20px"
|
fxLayoutGap="20px"
|
||||||
fxLayoutAlign="center end"
|
fxLayoutAlign="center end"
|
||||||
>
|
[ngClass]="{'scrolling': isScrolling}"
|
||||||
|
>
|
||||||
<a
|
<a
|
||||||
*ngFor="let link of menuLinks"
|
*ngFor="let link of menuLinks"
|
||||||
mat-button
|
mat-button
|
||||||
|
@ -16,8 +17,7 @@
|
||||||
(click)="onMenuClick(link.id)"
|
(click)="onMenuClick(link.id)"
|
||||||
[ngClass]="{'active': currentSection === link.id}"
|
[ngClass]="{'active': currentSection === link.id}"
|
||||||
id="{{link.id}}_menu_link"
|
id="{{link.id}}_menu_link"
|
||||||
>{{ link.label }}</a
|
>{{ link.label }}</a>
|
||||||
>
|
|
||||||
<div id="selected_indicator" [ngStyle]="{'top.px': activeLinkTop, 'opacity': showIndicator ? 1 : 0}"></div>
|
<div id="selected_indicator" [ngStyle]="{'top.px': activeLinkTop, 'opacity': showIndicator ? 1 : 0}"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,17 @@
|
||||||
#menu {
|
#menu {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: -300px;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
background-color: rgba(255, 255, 255, 0.8);
|
background-color: rgba(255, 255, 255, 0.8);
|
||||||
padding: 80px;
|
padding: 80px;
|
||||||
|
transition: all 1s ease-in-out;
|
||||||
|
|
||||||
|
&.scrolling {
|
||||||
|
right: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
transition: all 1s ease-in-out 0.5s;
|
transition: all 1s ease-in-out 0.5s;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {AfterViewInit, ChangeDetectionStrategy, Component, QueryList, ViewChildren} from '@angular/core';
|
import {AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, HostListener, QueryList, ViewChildren} from '@angular/core';
|
||||||
import {HeaderComponent} from './header/header.component';
|
import {HeaderComponent} from './header/header.component';
|
||||||
import {WelcomeComponent} from './welcome/welcome.component';
|
import {WelcomeComponent} from './welcome/welcome.component';
|
||||||
import {AboutUsComponent} from './about-us/about-us.component';
|
import {AboutUsComponent} from './about-us/about-us.component';
|
||||||
|
@ -35,8 +35,10 @@ export class AppComponent implements AfterViewInit {
|
||||||
currentSection = 'header';
|
currentSection = 'header';
|
||||||
activeLinkTop: number;
|
activeLinkTop: number;
|
||||||
showIndicator = false;
|
showIndicator = false;
|
||||||
|
isScrolling = false;
|
||||||
|
scrollTimer = -1;
|
||||||
|
|
||||||
constructor() {
|
constructor(private changeDetector: ChangeDetectorRef) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
|
@ -56,10 +58,25 @@ export class AppComponent implements AfterViewInit {
|
||||||
onSectionChange(sectionId: string) {
|
onSectionChange(sectionId: string) {
|
||||||
this.currentSection = sectionId;
|
this.currentSection = sectionId;
|
||||||
this.moveSelectedIndicator(this.currentSection);
|
this.moveSelectedIndicator(this.currentSection);
|
||||||
console.log('section change to:', sectionId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollTo(section) {
|
scrollTo(section) {
|
||||||
document.querySelector('#' + section).scrollIntoView();
|
document.querySelector('#' + section).scrollIntoView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('window:scroll')
|
||||||
|
onScroll() {
|
||||||
|
this.isScrolling = true;
|
||||||
|
if (this.scrollTimer !== -1) {
|
||||||
|
clearTimeout(this.scrollTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scrollTimer = setTimeout(() => {
|
||||||
|
this.showIndicator = true;
|
||||||
|
this.isScrolling = false;
|
||||||
|
this.scrollTimer = -1;
|
||||||
|
this.changeDetector.detectChanges();
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue