feat: add parallax infinite scroll hero for index
This commit is contained in:
parent
e9a666621f
commit
43e8dcff5e
5 changed files with 79 additions and 9 deletions
BIN
public/bg-clouds.png
Normal file
BIN
public/bg-clouds.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
BIN
public/bg-mountains.png
Normal file
BIN
public/bg-mountains.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
BIN
public/bg-trees.png
Normal file
BIN
public/bg-trees.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
|
|
@ -18,6 +18,10 @@
|
||||||
"content"
|
"content"
|
||||||
"footer";
|
"footer";
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,84 @@ import Layout from "../layouts/BaseLayout.astro";
|
||||||
<Layout>
|
<Layout>
|
||||||
<title slot="head">Home</title>
|
<title slot="head">Home</title>
|
||||||
<style>
|
<style>
|
||||||
.hero {
|
:root {
|
||||||
grid-area: hero;
|
--scroll-speed: 10s;
|
||||||
display: grid;
|
}
|
||||||
place-items: center;
|
.parallax-container {
|
||||||
padding: 4rem 2rem;
|
position: relative;
|
||||||
min-height: 60vh;
|
height: 208px;
|
||||||
background: #f8f9fa;
|
width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layer {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 1600vw; /* bg images are 160px, so use 16*vw for smooth scrolling */
|
||||||
|
background-repeat: round;
|
||||||
|
background-position: bottom;
|
||||||
|
background-size: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layer-back {
|
||||||
|
background-image: url("/bg-clouds.png");
|
||||||
|
z-index: 1;
|
||||||
|
animation: scroll calc(var(--scroll-speed) * 42) linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layer-middle {
|
||||||
|
background-image: url("/bg-mountains.png");
|
||||||
|
z-index: 2;
|
||||||
|
animation: scroll calc(var(--scroll-speed) * 32) linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layer-front {
|
||||||
|
background-image: url("/bg-trees.png");
|
||||||
|
z-index: 3;
|
||||||
|
animation: scroll calc(var(--scroll-speed) * 11) linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes scroll {
|
||||||
|
0% {
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
section#hero {
|
||||||
|
position: relative;
|
||||||
|
padding: 2rem;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.hero {
|
||||||
|
position: relative;
|
||||||
|
top: calc(-4 * 0.9rem);
|
||||||
|
left: 12px;
|
||||||
|
width: calc(100% - 24px);
|
||||||
|
}
|
||||||
|
div.hero > h1 {
|
||||||
|
color: #fff;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
div.hero > p {
|
||||||
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<Fragment slot="content">
|
<Fragment slot="content">
|
||||||
<section class="hero" id="hero">
|
<section id="hero">
|
||||||
<div>
|
<div class="parallax-container">
|
||||||
|
<div class="layer layer-back"></div>
|
||||||
|
<div class="layer layer-middle"></div>
|
||||||
|
<div class="layer layer-front"></div>
|
||||||
|
</div>
|
||||||
|
<div class="hero">
|
||||||
<h1>Lorem Ipsum</h1>
|
<h1>Lorem Ipsum</h1>
|
||||||
<p>
|
<p>
|
||||||
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
|
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue