Add responsive and lazy image loading

This commit is contained in:
Luca Bosin
2023-08-21 22:04:10 +02:00
parent 6ae22b7a9c
commit ca90df83e9
30 changed files with 197 additions and 101 deletions

View File

@ -11,6 +11,12 @@
*/
export let alt = undefined;
/**
* Whether the image is the first one in the viewport.
* @type {boolean}
*/
export let firstViewport = false;
/**
* The click handler for the image.
* @param {MouseEvent} event
@ -21,10 +27,12 @@
}
</script>
<a href="{src}" on:click={clickHandler}>
<figure class="photo">
<img src="{src}" alt="{alt}" />
</figure>
<a href={src} on:click={clickHandler}>
<picture>
<source media="(min-width: 850px)" srcset="{src}/t/l" />
<source media="(min-width: 450px)" srcset="{src}/t/m" />
<img src="{src}/t" {alt} loading={firstViewport ? 'eager' : 'lazy'} />
</picture>
</a>
<style>