/* ANGVIK EIENDOM – PARALLAX */
.angvik-eiendom-parallax {
position: relative;
left: 50%;
transform: translateX(-50%);
width: 100vw;
max-width: none !important;
height: 60vh;
min-height: 260px;
margin: 0;
padding: 0;
overflow: hidden;
isolation: isolate;
box-sizing: border-box;
}
/* Bakgrunnsbilde */
.angvik-eiendom-parallax__image {
position: absolute;
top: -55px;
left: 0;
width: 100%;
height: calc(100% + 110px);
background-image: url("https://angvikeiendom.no/wp-content/uploads/2022/09/Moldehallen-3-scaled.jpg");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
transform: translate3d(
0,
var(--parallax-offset, 0px),
0
);
will-change: transform;
pointer-events: none;
}
/* Mobilvisning */
@media (max-width: 768px) {
.angvik-eiendom-parallax {
height: auto;
min-height: 0;
aspect-ratio: 1 / 1;
}
.angvik-eiendom-parallax__image {
background-position: center center;
}
}
/* Redusert bevegelse */
@media (prefers-reduced-motion: reduce) {
.angvik-eiendom-parallax__image {
transform: none;
will-change: auto;
}
}
(function () {
const banners = document.querySelectorAll(
'.angvik-eiendom-parallax'
);
if (
!banners.length ||
window.matchMedia(
'(prefers-reduced-motion: reduce)'
).matches
) return;
let scheduled = false;
function updateParallax() {
scheduled = false;
banners.forEach(function (banner) {
const rect = banner.getBoundingClientRect();
if (
rect.bottom window.innerHeight
) return;
const center =
rect.top + rect.height / 2;
const distance =
center - window.innerHeight / 2;
/* Dempet parallax-bevegelse */
const maxMove = Math.min(
35,
rect.height * 0.1
);
const movement = Math.max(
-maxMove,
Math.min(maxMove, -distance * 0.1)
);
banner.style.setProperty(
'--parallax-offset',
movement.toFixed(1) + 'px'
);
});
}
function requestUpdate() {
if (!scheduled) {
scheduled = true;
requestAnimationFrame(updateParallax);
}
}
window.addEventListener(
'scroll',
requestUpdate,
{ passive: true }
);
window.addEventListener(
'resize',
requestUpdate
);
updateParallax();
})();