1

I am using React Spring for Parallax on a webpage however one of the components higher up on the page <Section2 /> uses flexbox to force 4 large horizontal icons to render as 2 x 2 icons on smaller screens.

When this happens it causes the offset value to be wrong for <Section3> in the mobile view. So the question I have is how do I change the offset value either by a media query or by other means.

Here is my code:

const Home = () => {

  return (
    <>
      <Layout>
        <SEO title="Home" />
        <Parallax pages={4}>
          <ParallaxLayer offset={0} speed={1} style={{ zIndex: '5' }}>
            <Hero />
          </ParallaxLayer>
          <ParallaxLayer offset={0.7} speed={1.4} style={{ zIndex: '10' }}>
            <HeroName />
          </ParallaxLayer>
          <ParallaxLayer
            offset={0.8}
            speed={0.7}
            style={{ zIndex: '-1', backgroundColor: '#fcf7f0' }}
          >
            <Section1 />
          </ParallaxLayer>
          <ParallaxLayer offset={1} speed={0.8} style={{ zIndex: '3' }}>
            <Section2 />
          </ParallaxLayer>
          <ParallaxLayer offset={1.2} speed={0.5} >
           <Section3 />
          </ParallaxLayer>
        </Parallax>
      </Layout>
    </>
  );
};  

Many thanks

1 Answer 1

1

I solved this by using a ternary . offset={window.innerWidth < 768 ? 2.1 : 1.2}

Sign up to request clarification or add additional context in comments.

2 Comments

What would happen on SSR?
SSR should rendering a mobile default, something like 650. So perhaps... typeof window !== "undefined" ? 650 : window.innerWidth < 768 ? 2.1 : 1.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.