Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Trying to change behaviour of img-dim setSrcset function #168

@cozarkd

Description

@cozarkd

Hi,
I'm trying to change this function to set sizes that makes sense to my project. I have a big full width/hero image for each post and then a thumbnail (that is the same img) for each post featured in home. So I thought that maybe I could change the code to identify a class like "small" for the thumbnails and work with the fallback for others images.

So my code is like this now:

async function setSrcset(img, src, format) {
  const setInfo = await srcset(src, format);
  img.setAttribute("srcset", setInfo.srcset);
  img.setAttribute(
    "sizes",
    // If the image has the class img-small"
    img.classList.contains("img-small")
    ? "(max-width: 608px) 110px, 164px"
    : "(max-width: 608px) 100vw, 1440px"
  );
  return setInfo.fallback;
}

but it doesn't work at all. I double checked the class on that tag (i have three css classes there). And the img-dim.js file is running because if I change the fallback (: "(max-width: 608px) 100vw, 1440px") it changes in the build.

Any idea why this could not be working? I'm lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions