Angular Материал меню рендеринга внизу страницы - PullRequest
0 голосов
/ 16 апреля 2020

Я только что добавил меню навигации в проект, и теперь меню отображается внизу страницы со следующими сгенерированными значениями стиля:

pointer-events: auto;
top: -1688.84px;   <-----??????
right: -140px;

Я добавляю пользовательский css класс, чтобы противостоять этому, но мне интересно, как материал заполняет это.

Navbar.component. html

<div class="main nav"  fxHide.lt-md>
  <ul>
    <li value={{i}} class="nav-item" *ngFor="let item of currentNavItems; let i = index">
      <a id="{{item}}" (click)="scroll($event)">{{item}}</a>
    </li>
  </ul>
</div>
<div class="mobile" fxHide.gt-sm>
  <button mat-icon-button [matMenuTriggerFor]="navbar">
    <mat-icon  style="color: #e2d4ce; font-size:64px">menu</mat-icon>
  </button>
  <mat-menu #navbar="matMenu" >
    <div *ngFor="let item of currentNavItems; let i = index">
   <button mat-menu-item id="{{item}}" >{{item}}</button>
    </div>
  </mat-menu>

</div>

Navbar.component.ts

import { NavService } from './../nav.service';
import { Router } from '@angular/router';
import { Component, OnInit, Input } from '@angular/core';
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout'
import { MatMenu } from '@angular/material/menu';

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
   navbar:MatMenu;
  isHome:boolean
  mobile:boolean;;
  currentNavItems:string[] = ["ABOUT","NEWS","EVENTS","RETREAT","ARTIST OF THE MONTH"];
  constructor(public router:Router, private ns:NavService, public BreakpointObserver: BreakpointObserver) {}

  home: boolean;
  ngOnInit(): void {
    this.BreakpointObserver.observe([
      '(min-width:400px)'
    ]).subscribe((state:BreakpointState) =>{
      if(state.matches){
        this.mobile = true
      }else{
        this.mobile=false;
      }
    })
  }

scroll(event){
    console.log(event.target.id)
    let id = event.target.id.toLowerCase()
    id === "artist of the month" ? id ="artist" : id=id

    const yourElement = document.getElementById(id+"-scroll");
    const y = yourElement.getBoundingClientRect().top + window.pageYOffset;
    window.scrollTo({top: y, behavior: 'smooth'})
  }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...