Responsive images

This commit is contained in:
2023-11-04 20:52:50 +01:00
parent 64f5490de6
commit 25795460e6
14 changed files with 25 additions and 10 deletions

View File

@@ -2,9 +2,9 @@
import type IImage from '$lib/interfaces/IImage'; import type IImage from '$lib/interfaces/IImage';
let images: IImage[] = [ let images: IImage[] = [
{ url: 'IMG_5613.jpeg', alt: 'Kevin at beach' }, { name: 'fish', alt: 'Kevin fishing' },
{ url: 'IMG_4551.jpeg', alt: 'Kevin fishing' }, { name: 'boat', alt: 'Kevin in a boat with dog' },
{ url: 'IMG_1925.jpeg', alt: 'Kevin in a boat with dog' } { name: 'sand', alt: 'Kevin at beach' }
]; ];
function cycle() { function cycle() {
@@ -20,8 +20,13 @@
role="button" role="button"
tabindex="0" tabindex="0"
> >
{#each images as image (image.url)} {#each images as image (image.name)}
<img src="/images/{image.url}" alt={image.alt} /> <picture>
<source media="(max-width: 420px)" srcset="/images/{image.name}-300w.jpeg" />
<source media="(max-width: 1800px)" srcset="/images/{image.name}-620w.jpeg" />
<source media="(min-width: 1801px)" srcset="/images/{image.name}-900w.jpeg" />
<img src="/images/{image.name}-300w.jpeg" alt={image.alt} />
</picture>
{/each} {/each}
</div> </div>
@@ -33,18 +38,28 @@
-webkit-user-select: none; -webkit-user-select: none;
margin-left: 40px; margin-left: 40px;
img { picture {
position: absolute; position: absolute;
margin-top: 10vh; margin-top: 10vh;
max-height: 80vh;
transition: all 0.51s ease; transition: all 0.51s ease;
} }
img {
max-width: 42vw;
}
@for $i from 0 through 4 { @for $i from 0 through 4 {
img:nth-of-type(#{$i}) { picture:nth-of-type(#{$i}) {
left: calc(-10px * $i); left: calc(-10px * $i);
top: calc(-10px * $i); top: calc(-10px * $i);
} }
} }
} }
@media (max-width: 500px) {
div.images img {
margin-bottom: 3rem;
max-width: 80vw;
}
}
</style> </style>

View File

@@ -1,6 +1,6 @@
interface IImage { interface IImage {
url: string; name: string;
alt: string; alt: string;
} }
export type { IImage }; export default IImage;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 524 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB