Skip to content

Commit

Permalink
add: random image to hero banners
Browse files Browse the repository at this point in the history
  • Loading branch information
pratapmaharana committed Jun 9, 2023
1 parent ee3d3d6 commit 41e2eef
Showing 1 changed file with 79 additions and 82 deletions.
161 changes: 79 additions & 82 deletions src/lib/home/HeroBanners.svelte
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
<script>
import LazyImg from '$lib/components/Image/LazyImg.svelte'
export let heroBanners
</script>

{#if heroBanners?.length > 0}
<div>
<div class="grid grid-cols-1 sm:grid-cols-2">
<a
href="{heroBanners[0]?.link || '##'}"
aria-label="Click here to view the banner's related products"
>
<LazyImg
src="{heroBanners[0]?.img}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full w-full object-cover"
/>
</a>

<a
href="{heroBanners[1]?.link || '##'}"
aria-label="Click here to view the banner's related products"
>
<LazyImg
src="{heroBanners[1]?.img}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full w-full object-cover"
/>
</a>
</div>

<div class="grid grid-cols-1 sm:grid-cols-2">
<div class="grid grid-cols-2">
<a
href="{heroBanners[2]?.link || '##'}"
aria-label="Click here to view the banner's related products"
>
<LazyImg
src="{heroBanners[2]?.img}"
alt=""
height="390"
aspect_ratio="1:1"
class="col-span-1 h-full w-full object-cover"
/>
</a>

<a
href="{heroBanners[2]?.link || '##'}"
aria-label="Click here to view the banner's related products"
>
<LazyImg
src="{heroBanners[3]?.img}"
alt=""
height="390"
aspect_ratio="1:1"
class="col-span-1 h-full w-full object-cover"
/>
</a>
</div>

<div>
<a
href="{heroBanners[4]?.link || '##'}"
aria-label="Click here to view the banner's related products"
>
<LazyImg
src="{heroBanners[4]?.img}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full w-full object-cover"
/>
</a>
</div>
</div>
</div>
{/if}
<script>
import LazyImg from '$lib/components/Image/LazyImg.svelte'
export let heroBanners
function generateRandomImage() {
const randomNum = Math.floor(Math.random() * 10) // Generates a random number between 0 and 9
// Replace the image source with a random image URL
return 'https://source.unsplash.com/random/' + randomNum
}
</script>

{#if heroBanners?.length > 0}
<div>
<div class="grid grid-cols-1 sm:grid-cols-2">
<a
href="{heroBanners[0]?.link || '##'}"
aria-label="Click here to view the banner's related products">
<LazyImg
src="{heroBanners[0]?.img || generateRandomImage()}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full max-h-[390px] w-full object-cover aspect-video" />
</a>

<a
href="{heroBanners[1]?.link || '##'}"
aria-label="Click here to view the banner's related products">
<LazyImg
src="{heroBanners[1]?.img || generateRandomImage()}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full max-h-[390px] w-full object-cover aspect-video" />
</a>
</div>

<div class="grid grid-cols-1 sm:grid-cols-2">
<div class="grid grid-cols-2">
<a
href="{heroBanners[2]?.link || '##'}"
aria-label="Click here to view the banner's related products">
<LazyImg
src="{heroBanners[2]?.img || generateRandomImage()}"
alt=""
height="390"
aspect_ratio="1:1"
class="col-span-1 h-full max-h-[390px] w-full object-cover aspect-square" />
</a>

<a
href="{heroBanners[2]?.link || '##'}"
aria-label="Click here to view the banner's related products">
<LazyImg
src="{heroBanners[3]?.img || generateRandomImage()}"
alt=""
height="390"
aspect_ratio="1:1"
class="col-span-1 h-full max-h-[390px] w-full object-cover aspect-square" />
</a>
</div>

<div>
<a
href="{heroBanners[4]?.link || '##'}"
aria-label="Click here to view the banner's related products">
<LazyImg
src="{heroBanners[4]?.img || generateRandomImage()}"
alt=""
height="390"
aspect_ratio="2:1"
class="col-span-1 h-full max-h-[390px] w-full object-cover aspect-video" />
</a>
</div>
</div>
</div>
{/if}

1 comment on commit 41e2eef

@vercel
Copy link

@vercel vercel bot commented on 41e2eef Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.