Skip to content

Commit

Permalink
Merge pull request #330 from IrisShaders/banner-image
Browse files Browse the repository at this point in the history
feat: Randomized Banner Images
  • Loading branch information
jbritain authored Sep 30, 2024
2 parents 16a4b15 + bbda104 commit 991cb24
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 3 deletions.
Binary file added public/banners/1.webp
Binary file not shown.
Binary file added public/banners/2.webp
Binary file not shown.
Binary file added public/banners/3.webp
Binary file not shown.
Binary file added public/banners/4.webp
Binary file not shown.
Binary file added public/banners/5.webp
Binary file not shown.
Binary file added public/banners/6.webp
Binary file not shown.
Binary file removed src/assets/banner.webp
Binary file not shown.
20 changes: 20 additions & 0 deletions src/components/BannerImage.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
import fs from 'fs';
import type { Props } from '@astrojs/starlight/props';
const imageFiles = fs.readdirSync("./public/banners");
---

<div id="banner-img">a</div>

<script define:vars={{imageFiles}}>
document.addEventListener('DOMContentLoaded', () => {
const bannerImage = document.querySelector("#banner-img");
const randomIndex = Math.floor(Math.random() * imageFiles.length);
const randomImage = `/banners/${imageFiles[randomIndex]}`;

bannerImage.style.backgroundImage = `url(${randomImage})`;
});
</script>

4 changes: 3 additions & 1 deletion src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ hero:

import { Card, CardGrid } from '@astrojs/starlight/components';

<div class="bg-img"></div>
import BannerImage from '../../components/BannerImage.astro'

<BannerImage />

## Get Started

Expand Down
4 changes: 2 additions & 2 deletions src/styles/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
--background-image-opacity: 1.0;
}

.bg-img {
#banner-img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 130vh;
opacity: var(--background-image-opacity);
background: url(../assets/banner.webp);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
mask-image: linear-gradient(to bottom, rgba(0,0,0,1), rgba(0,0,0,0));
z-index: -1;
}

0 comments on commit 991cb24

Please sign in to comment.