You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

5 years ago
import { Component, OnInit, HostListener, Inject } from '@angular/core'
import { Router, NavigationEnd } from '@angular/router'
5 years ago
import { DOCUMENT } from '@angular/common'
5 years ago
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit {
5 years ago
public isSticky: boolean = false
public isMenuOpen: boolean = false
public isFirstScroll: boolean = true
5 years ago
constructor(@Inject(DOCUMENT) private document: Document, private router: Router) {
router.events.subscribe((val) => {
this.isMenuOpen = false
this.isSticky = true
this.document.body.classList.remove('no-scroll')
})
}
5 years ago
ngOnInit(): void {
}
5 years ago
@HostListener('window:scroll', ['$event'])
onScroll(event) {
const verticalOffset = window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop || 0
this.isFirstScroll = this.router.url == '/'
this.isSticky = this.isFirstScroll ? this.isMenuOpen || verticalOffset > 10 : true
5 years ago
}
toggleMenu(): void {
this.isMenuOpen = !this.isMenuOpen
if(this.isMenuOpen) {
this.isSticky = true
this.document.body.classList.add('no-scroll')
} else {
this.document.body.classList.remove('no-scroll')
}
}
5 years ago
}