gatsby-background-image icon indicating copy to clipboard operation
gatsby-background-image copied to clipboard

Art direction not changing images on breakpoints.

Open HenrikDK2 opened this issue 5 years ago • 5 comments

On render it checks the breakpoint, but on window resize it doesn't switch out the image to the specified media query.

So in this example if the screen size is below 960px it will render a different image, but if i resize the window above 960px it doesn't switch out the image like it does in gatsby-image.

TLDR: Doesn't switch images on window resize.

...
const query = graphql`
  query {
    desktop: file(name: { eq: "bg" }, relativeDirectory: { eq: "movie" }) {
      childImageSharp {
        fluid(quality: 100, maxWidth: 3000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
    mobile: file(name: { eq: "bgMobile" }, relativeDirectory: { eq: "movie" }) {
      childImageSharp {
        fluid(quality: 100, maxWidth: 3000) {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }
`;

const Movie = () => {
  const { mobile, desktop } = useStaticQuery(query);
  const sources = [
    mobile.childImageSharp.fluid,
    {
      ...desktop.childImageSharp.fluid,
      media: `(min-width: 960px)`,
    },
  ];

  return (
    <Section critical Tag="section" fluid={sources}>
        ...
    </Section>
  );
};

HenrikDK2 avatar Oct 29 '20 10:10 HenrikDK2

Hi @HenrikDK2,

could you tell me in which Browsers & if it does change them on reload? Far more info necessary for

TLDR: Doesn't switch images on window resize.

(and why it should change on resize? ; )

Best,

Tim.

timhagn avatar Nov 04 '20 11:11 timhagn

Hi there! As @timhagn momentarily is the main contributor to this package, this issue has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs, though we're open to suggestions on how to get more maintainers! Thank you for your contributions : )!

github-actions[bot] avatar Nov 28 '20 00:11 github-actions[bot]

It does change background images on reload, the problem is the functionality that doesn't resemble gatsby-image. Making background-image change on breakpoints when resized can make it more responsive. Some layouts depends on the background. If the background doesn't change when the device dimensions changes (Like changing orientation) it no longer haves the correct Image which may or may not ruin the layout.

HenrikDK2 avatar Nov 28 '20 20:11 HenrikDK2

Ah, OK, now I get you. Uffz, that's a heavy one - as art direction is achieved by extracted media-queries. And I guess - will have to test it - that's why it doesn't change... Workaround (for the moment): ResizeObserver with key change on resize.

timhagn avatar Nov 28 '20 21:11 timhagn

Any updates or workarounds here? I'm currently having to display two copies of data with two separate background images which doesn't allow for SSR

twhitson avatar Dec 10 '20 16:12 twhitson