link up menu items to page anchors on components

This commit is contained in:
eleanor 2018-11-07 10:56:32 -05:00
parent 6fa059e049
commit 4f6e3497fc
7 changed files with 44 additions and 9 deletions

View File

@ -1,5 +1,6 @@
<div
class="about-us"
id="about-us"
>
<h1>ABOUT US</h1>
<div

View File

@ -1,3 +1,6 @@
<div class="case-studies">
<div
class="case-studies"
id="case-studies"
>
<h1>CASE STUDIES</h1>
</div>

View File

@ -1,3 +1,6 @@
<div class="contact">
<div
class="contact-us"
id="contact-us"
>
<h1>CONTACT US</h1>
</div>

View File

@ -1,4 +1,4 @@
.contact {
.contact-us {
background-image: url("../../assets/images/astro_clock.jpg");
background-size: cover;
min-height: 300px;

View File

@ -5,17 +5,32 @@
<mat-menu #menu="matMenu">
<button
mat-menu-item
onclick=""
(click)="scroll()"
>
<span>HOME</span>
</button>
<button
mat-menu-item
(click)="scroll('about-us')"
>
<span>ABOUT US</span>
</button>
<button mat-menu-item>
<button
mat-menu-item
(click)="scroll('case-studies')"
>
<span>CASE STUDIES</span>
</button>
<button mat-menu-item>
<button
mat-menu-item
(click)="scroll('reviews')"
>
<span>WHAT PEOPLE SAY</span>
</button>
<button mat-menu-item>
<button
mat-menu-item
(click)="scroll('contact-us')"
>
<span>CONTACT US</span>
</button>
</mat-menu>

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ViewportScroller } from '@angular/common';
@Component({
selector: 'app-menu',
@ -7,9 +8,18 @@ import { Component, OnInit } from '@angular/core';
})
export class MenuComponent implements OnInit {
constructor() {}
constructor(
private viewportScroller: ViewportScroller
) {}
ngOnInit() {
}
scroll(anchor: string) {
if (anchor) {
this.viewportScroller.scrollToAnchor(anchor);
} else {
this.viewportScroller.scrollToPosition([0, 0]);
}
}
}

View File

@ -1,3 +1,6 @@
<div class="reviews">
<div
class="reviews"
id="reviews"
>
<h1>WHAT PEOPLE SAY</h1>
</div>