Fix header background position logic on scroll
Updated the header's background position calculation to use string concatenation for `inverseYPos` and introduced dynamic adjustment of `inverseYPos` on scroll. This ensures smoother and more accurate background position updates.
This commit is contained in:
parent
04c5a3e846
commit
1af614323e
|
|
@ -1,12 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<ng-container>
|
<ng-container>
|
||||||
<header id="top"
|
<header id="top"
|
||||||
[ngStyle]="{ 'background-image': getBackgroundImage(), 'height': height, 'background-position': center {{ inverseYPos }}px; }">
|
[ngStyle]="{ 'background-image': getBackgroundImage(), 'height': height, 'background-position': 'center ' + inverseYPos + 'px' }">
|
||||||
<nav id="nav" [ngClass]="active">
|
<nav id="nav" [ngClass]="active">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div id="mobile_nav">
|
<div id="mobile_nav">
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,14 @@ export class HeaderComponent {
|
||||||
@Input() overlay_gradient: number = 0;
|
@Input() overlay_gradient: number = 0;
|
||||||
|
|
||||||
public active: string = '';
|
public active: string = '';
|
||||||
|
public inverseYPos: number = 0;
|
||||||
|
|
||||||
@HostListener('window:scroll', [])
|
@HostListener('window:scroll', [])
|
||||||
onWindowScroll(): void {
|
onWindowScroll(): void {
|
||||||
const scrollPosition = window.scrollY;
|
const scrollPosition = window.scrollY;
|
||||||
if (scrollPosition > 0) {
|
if (scrollPosition > 0) {
|
||||||
this.active = 'active';
|
this.active = 'active';
|
||||||
|
this.inverseYPos = (scrollPosition / 4) * -1;
|
||||||
} else {
|
} else {
|
||||||
this.active = '';
|
this.active = '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user