Skip to content

Commit 5462f0e

Browse files
committed
refactor: split layered hero image from layered recipe image
1 parent 0913daa commit 5462f0e

3 files changed

Lines changed: 84 additions & 44 deletions

File tree

src/components/hero/HeroBowl.astro

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
---
2-
import { Image } from 'astro:assets';
3-
import heroBowl from "../../images/hero-bowl.png";
42
import heroBowl1 from "../../images/hero-bowl-1.png";
53
import heroBowl2 from "../../images/hero-bowl-2.png";
64
import heroBowl3 from "../../images/hero-bowl-3.png";
75
import heroBowl4 from "../../images/hero-bowl-4.png";
8-
import LayeredRecipeImage from '../recipe-card/LayeredRecipeImage.astro';
6+
import LayeredHeroImage from './LayeredHeroImage.astro';
97
108
const baseUrl = import.meta.env.BASE_URL;
119
---
1210

1311
<div class="image-container">
14-
<LayeredRecipeImage
12+
<LayeredHeroImage
1513
class="bowl-image"
1614
imageLayers={[heroBowl1, heroBowl2, heroBowl3, heroBowl4]}
1715
title="Signature Bowl"
18-
animate={true}
1916
/>
2017
<video width="1280" height="720" autoplay muted loop playsinline>
2118
<source src=`${baseUrl}/steam.webm` type="video/webm">
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
import { Image } from 'astro:assets';
3+
4+
interface Props {
5+
imageLayers: ImageMetadata[];
6+
title: string;
7+
width?: number;
8+
height?: number;
9+
class?: string;
10+
}
11+
12+
const { imageLayers, title, width, height, class: className } = Astro.props;
13+
---
14+
15+
<div class:list={["overlay-container", "animate", className]}>
16+
{imageLayers.map((img, index) => (
17+
<Image
18+
src={img}
19+
alt={title}
20+
width={width}
21+
height={height}
22+
class={`hero-image-layer-${index}`}
23+
/>
24+
))}
25+
</div>
26+
27+
<style lang="scss">
28+
.overlay-container {
29+
display: grid;
30+
grid-template-areas: "overlay";
31+
32+
:global(> *) {
33+
grid-area: overlay;
34+
min-width: 0;
35+
}
36+
}
37+
38+
img {
39+
box-sizing: border-box;
40+
max-width: 100%;
41+
height: auto;
42+
object-fit: contain;
43+
object-position: center;
44+
}
45+
46+
.animate {
47+
img {
48+
animation: MoveUpDown 5s ease infinite;
49+
}
50+
51+
.hero-image-layer-0 {
52+
--move-distance: 10px;
53+
animation-delay: 0s;
54+
}
55+
56+
.hero-image-layer-1 {
57+
--move-distance: 8px;
58+
animation-delay: -0.4s;
59+
}
60+
61+
.hero-image-layer-2 {
62+
--move-distance: 7px;
63+
animation-delay: -0.8s;
64+
}
65+
66+
.hero-image-layer-3 {
67+
--move-distance: 6px;
68+
animation-delay: -1.2s;
69+
}
70+
71+
@keyframes MoveUpDown {
72+
0%, 100% {
73+
transform: translateY(0);
74+
}
75+
50% {
76+
transform: translateY(var(--move-distance));
77+
}
78+
}
79+
}
80+
</style>

src/components/recipe-card/LayeredRecipeImage.astro

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ interface Props {
77
title: string;
88
width?: number;
99
height?: number;
10-
animate?: boolean;
1110
class?: string;
1211
}
1312
14-
const { imageLayers, title, width, height, animate, class: className } = Astro.props;
13+
const { imageLayers, title, width, height, class: className } = Astro.props;
1514
---
1615

17-
<div class:list={["overlay-container", animate ? "animate" : undefined, className]}>
16+
<div class:list={["overlay-container", className]}>
1817
{imageLayers.map((img, index) => (
1918
<CardContent translateZ={(imageLayers.length * -5) + (index + 1) * 10}>
2019
<Image
@@ -23,7 +22,6 @@ const { imageLayers, title, width, height, animate, class: className } = Astro.p
2322
width={width}
2423
height={height}
2524
transition:name={`recipe-image-${title}-${index}`}
26-
class={`recipe-image-layer-${index}`}
2725
/>
2826
</CardContent>
2927
))}
@@ -49,39 +47,4 @@ const { imageLayers, title, width, height, animate, class: className } = Astro.p
4947
object-position: center;
5048
transition: transform .2s;
5149
}
52-
53-
.animate {
54-
img {
55-
animation: MoveUpDown 5s ease infinite;
56-
}
57-
58-
.recipe-image-layer-0 {
59-
--move-distance: 10px;
60-
animation-delay: 0s;
61-
}
62-
63-
.recipe-image-layer-1 {
64-
--move-distance: 8px;
65-
animation-delay: -0.4s;
66-
}
67-
68-
.recipe-image-layer-2 {
69-
--move-distance: 7px;
70-
animation-delay: -0.8s;
71-
}
72-
73-
.recipe-image-layer-3 {
74-
--move-distance: 6px;
75-
animation-delay: -1.2s;
76-
}
77-
78-
@keyframes MoveUpDown {
79-
0%, 100% {
80-
transform: translateY(0);
81-
}
82-
50% {
83-
transform: translateY(var(--move-distance));
84-
}
85-
}
86-
}
8750
</style>

0 commit comments

Comments
 (0)