-
-
Notifications
You must be signed in to change notification settings - Fork 279
Expand file tree
/
Copy path_EnforceAspectRatio.svelte
More file actions
39 lines (37 loc) · 909 Bytes
/
_EnforceAspectRatio.svelte
File metadata and controls
39 lines (37 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<ImageList class="my-image-list-enforce-ratio">
{#each Array(15) as _unused, i}
<Item>
<ImageAspectContainer>
<Image
tag="div"
style="background-image: url(https://placehold.co/190x{getUnevenImageSize(
i,
190,
10,
)}?text=190x{getUnevenImageSize(i, 190, 10)});"
/>
</ImageAspectContainer>
<Supporting>
<Label>Image {i + 1}</Label>
</Supporting>
</Item>
{/each}
</ImageList>
<script lang="ts">
import ImageList, {
Item,
ImageAspectContainer,
Image,
Supporting,
Label,
} from '@smui/image-list';
function getUnevenImageSize(
counter: number,
base: number,
variance: number,
preAdd = (num: number) => num,
) {
const mid = (counter % 2 ? Math.cos : Math.sin)(counter) * variance;
return base + Math.floor(preAdd(mid));
}
</script>