fix: PhotoSwipe not getting the real image dimensions

This is because `img.width.toString()` returns the `<img>` element dimension, not the real image dimension (stored in the `width` attribute).

closes https://github.com/CaiJimmy/hugo-theme-stack/issues/934
This commit is contained in:
Jimmy Cai 2024-02-05 17:43:25 +01:00
parent 47a57a2ad2
commit 4d6b65f63c

View file

@ -61,8 +61,8 @@ export default (container: HTMLElement) => {
const a = document.createElement('a');
a.href = img.src;
a.setAttribute('target', '_blank');
a.setAttribute('data-pswp-width', img.width.toString());
a.setAttribute('data-pswp-height', img.height.toString());
a.setAttribute('data-pswp-width', img.getAttribute('width'));
a.setAttribute('data-pswp-height', img.getAttribute('height'));
img.parentNode.insertBefore(a, img);
a.appendChild(img);
}