mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
refactor(gallery): calculate flex-basis & flex-grow on generation
Reduce layout shift
This commit is contained in:
parent
69cd9343a0
commit
474d7911e8
@ -83,8 +83,7 @@ class StackGallery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap adjacent figure tags with div.gallery, and append style
|
* Wrap adjacent figure tags with div.gallery
|
||||||
* Reference: https://github.com/xieranmaya/blog/issues/6
|
|
||||||
* @param figures
|
* @param figures
|
||||||
*/
|
*/
|
||||||
public static wrap(figures: HTMLElement[]) {
|
public static wrap(figures: HTMLElement[]) {
|
||||||
@ -97,12 +96,6 @@ class StackGallery {
|
|||||||
parentNode.insertBefore(galleryContainer, first)
|
parentNode.insertBefore(galleryContainer, first)
|
||||||
|
|
||||||
for (const figure of figures) {
|
for (const figure of figures) {
|
||||||
const width = figure.querySelector('img').width,
|
|
||||||
height = figure.querySelector('img').height;
|
|
||||||
|
|
||||||
figure.style.flexGrow = `${width * 100 / height}`;
|
|
||||||
figure.style.flexBasis = `${width * 240 / height}px`;
|
|
||||||
|
|
||||||
galleryContainer.appendChild(figure);
|
galleryContainer.appendChild(figure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
{{- with $alt -}}
|
{{- with $alt -}}
|
||||||
{{- $caption = . | safeHTML -}}
|
{{- $caption = . | safeHTML -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<figure>
|
<figure style="flex-grow: {{ $image.Width * 100 / $image.Height }}; flex-basis: {{ $image.Width * 240 / $image.Height }}">
|
||||||
<a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}">
|
<a href="{{ $image.RelPermalink }}" data-size="{{ $image.Width }}x{{ $image.Height }}">
|
||||||
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
|
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
|
||||||
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
|
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
|
||||||
|
Loading…
Reference in New Issue
Block a user