mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-28 19:43:31 +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
|
||||
* Reference: https://github.com/xieranmaya/blog/issues/6
|
||||
* Wrap adjacent figure tags with div.gallery
|
||||
* @param figures
|
||||
*/
|
||||
public static wrap(figures: HTMLElement[]) {
|
||||
@ -97,12 +96,6 @@ class StackGallery {
|
||||
parentNode.insertBefore(galleryContainer, first)
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
{{- with $alt -}}
|
||||
{{- $caption = . | safeHTML -}}
|
||||
{{- 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 }}">
|
||||
<img srcset="{{ $small.RelPermalink }} 480w, {{ $big.RelPermalink }} 1024w"
|
||||
src="{{ $image.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}" loading="lazy"
|
||||
|
Loading…
Reference in New Issue
Block a user