Content & marketing
Parallax Split Depth code
Copy the implementation or inspect every file that belongs to this component unit.
resources/views/components/ui/parallax-split-depth.blade.php
@props([
'image',
'alt' => '',
'eyebrow' => null,
'title' => null,
'description' => null,
'overlayClass' => 'bg-gradient-to-r from-gray-950/88 via-gray-950/50 to-gray-950/86',
])
@php
/*
| Split-depth parallax. Copy, glass panels and the framed image each move at
| a different rate to create a composed editorial hero.
*/
@endphp
<section
x-data="{
px: 0, py: 0,
reduced: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
move($event) {
if (this.reduced) {
return;
}
const rect = $el.getBoundingClientRect();
this.px = (($event.clientX - rect.left) / rect.width) - 0.5;
this.py = (($event.clientY - rect.top) / rect.height) - 0.5;
},
reset() {
this.px = 0;
this.py = 0;
},
}"
@mousemove="move($event)"
@mouseleave="reset()"
{{ $attributes->merge(['class' => 'relative isolate flex min-h-screen overflow-hidden bg-gray-950']) }}
>
<img
src="{{ $image }}"
alt="{{ $alt }}"
@if ($alt === '') aria-hidden="true" @endif
class="pointer-events-none absolute inset-0 -z-20 h-full w-full scale-[1.12] object-cover opacity-70 blur-[1px] will-change-transform motion-reduce:scale-100 motion-reduce:transform-none"
style="transform: translate3d(0, 0, 0) scale(1.12);"
:style="reduced ? 'transform: translate3d(0, 0, 0) scale(1);' : `transform: translate3d(${px * -42}px, ${py * -30}px, 0) scale(1.12);`"
>
<div class="absolute inset-0 -z-10 {{ $overlayClass }}" aria-hidden="true"></div>
<div class="mx-auto grid w-full max-w-7xl items-center gap-12 px-6 py-16 sm:px-8 lg:grid-cols-[0.82fr_1.18fr] lg:px-10">
<div
class="max-w-xl will-change-transform"
:style="reduced ? '' : `transform: translate3d(${px * 30}px, ${py * 18}px, 0);`"
>
@if ($eyebrow)
<x-ui.badge variant="brand" icon="columns" class="bg-white/12 text-white ring-1 ring-white/20 backdrop-blur dark:bg-white/12 dark:text-white">
{{ $eyebrow }}
</x-ui.badge>
@endif
@if ($title)
<h2 class="mt-5 text-4xl font-semibold tracking-tight text-white text-balance sm:text-6xl">{{ $title }}</h2>
@endif
@if ($description)
<p class="mt-5 text-base leading-7 text-white/78 text-pretty sm:text-lg">{{ $description }}</p>
@endif
@isset($actions)
<div class="mt-8 flex flex-col gap-3 sm:flex-row">{{ $actions }}</div>
@endisset
</div>
<div class="relative min-h-[34rem]">
<div
class="absolute inset-x-0 top-8 mx-auto h-[28rem] max-w-2xl overflow-hidden rounded-[2rem] border border-white/15 bg-white/10 shadow-2xl shadow-gray-950/60 will-change-transform"
:style="reduced ? '' : `transform: perspective(1000px) rotateX(${py * -7}deg) rotateY(${px * 10}deg) translate3d(${px * -24}px, ${py * -18}px, 0);`"
>
<img src="{{ $image }}" alt="" class="h-full w-full scale-110 object-cover">
<div class="absolute inset-0 bg-gradient-to-t from-gray-950/80 via-transparent to-white/10" aria-hidden="true"></div>
</div>
<div
class="absolute left-0 top-0 hidden w-56 rounded-2xl border border-white/15 bg-white/10 p-5 text-white shadow-2xl shadow-gray-950/50 backdrop-blur-md will-change-transform md:block"
:style="reduced ? '' : `transform: translate3d(${px * 82}px, ${py * 62}px, 0) rotate(${px * 8}deg);`"
aria-hidden="true"
>
<p class="text-sm font-semibold">Copy plane</p>
<p class="mt-2 text-sm leading-6 text-white/68">Foreground UI floats faster than the framed image.</p>
</div>
<div
class="absolute bottom-8 right-0 hidden w-64 rounded-2xl border border-brand-300/25 bg-brand-950/45 p-5 text-white shadow-2xl shadow-gray-950/50 backdrop-blur-md will-change-transform md:block"
:style="reduced ? '' : `transform: translate3d(${px * -92}px, ${py * -58}px, 0) rotate(${px * -7}deg);`"
aria-hidden="true"
>
<p class="text-sm font-semibold">Framed depth</p>
<p class="mt-2 text-sm leading-6 text-white/68">A split layout makes the parallax feel composed instead of decorative.</p>
</div>
</div>
</div>
</section>