Smooth scroll: Fix headerOffset in mobile
This commit is contained in:
parent
2492f737b8
commit
437a5fa50d
|
@ -239,4 +239,8 @@ export class LayoutService {
|
|||
get isMobile(): Observable<boolean> {
|
||||
return this.isMobileSubject.asObservable();
|
||||
}
|
||||
|
||||
get isMobileValue(): boolean {
|
||||
return this.isMobileSubject.getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import {ActivationStart, NavigationEnd, Router} from '@angular/router';
|
||||
import {Injectable, Type} from '@angular/core';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {LayoutService} from "../dashboard/sharedComponents/sidebar/layout.service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
@ -12,7 +13,7 @@ export class SmoothScroll {
|
|||
private currentComponent: string;
|
||||
private extraOffset: number = 0;
|
||||
|
||||
constructor(private router: Router) {
|
||||
constructor(private router: Router, private layoutService: LayoutService) {
|
||||
if (typeof window !== "undefined") {
|
||||
this.sub = router.events.subscribe(event => {
|
||||
if (event instanceof ActivationStart) {
|
||||
|
@ -21,7 +22,7 @@ export class SmoothScroll {
|
|||
this.currentComponent = event.snapshot.component.name;
|
||||
}
|
||||
} else if (event instanceof NavigationEnd) {
|
||||
let headerOffset = Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--header-height')) + 35;
|
||||
let headerOffset = (this.layoutService.isMobileValue?0:Number.parseInt(getComputedStyle(document.documentElement).getPropertyValue('--header-height'))) + 35;
|
||||
if(!this.router.getCurrentNavigation().extras?.state?.disableScroll) {
|
||||
if (this.interval) {
|
||||
clearInterval(this.interval);
|
||||
|
@ -46,7 +47,7 @@ export class SmoothScroll {
|
|||
position = element.getBoundingClientRect().top;
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
const y = element.getBoundingClientRect().top + window.pageYOffset + yOffset;
|
||||
const y = element.getBoundingClientRect().top + window.scrollY + yOffset;
|
||||
window.scrollTo({top: y, behavior: 'smooth'});
|
||||
}
|
||||
}, 50);
|
||||
|
|
Loading…
Reference in New Issue