support images

This commit is contained in:
Oskar Wickström
2024-08-22 17:08:58 +02:00
parent dcba7ef18b
commit c88ee9ac50
5 changed files with 36 additions and 2 deletions

12
index.js Normal file
View File

@@ -0,0 +1,12 @@
// Set the ratio variable on each image.
document.querySelectorAll("img").forEach(img => {
function onLoaded() {
const ratio = img.naturalWidth / img.naturalHeight;
img.style.setProperty("--ratio", ratio);
}
if (img.loaded) {
onLoaded();
} else {
img.addEventListener("load", onLoaded);
}
});