I am trying to pin the header ".typo" when the scroll position gets to the center of the viewport but the element(header) skips/jumps to the end position. Your help will be greatly appreciated as i have been stuck on this for days now.
import { Box, Container, Stack, Typography } from "@mui/material";
import Head from "next/head";
import Image from "next/image";
import Project from "../Components/Project";
import { gsap } from "gsap/dist/gsap";
import { ScrollTrigger } from "gsap/dist/ScrollTrigger";
import { useLayoutEffect, useRef } from "react";
gsap.registerPlugin(ScrollTrigger);
export default function Home() {
const headerRef = useRef(null);
useLayoutEffect(() => {
let ctx = gsap.context(() => {
gsap.to(
".typo",
{
scrollTrigger: {
trigger: ".typo",
markers: true,
start: "top center",
end: "bottom 30%",
scrub: true,
pin: true,
// pinSpacing: false,
},
},
headerRef
);
});
return () => ctx.revert;
}, []);
return (
<div>
<Head>
<title>Nate Port</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main>
<Container maxWidth="xl" sx={{ overflowX: "hidden" }}>
<Box sx={{ height: "100vh" }} />
<Stack
ref={headerRef}
justifyContent="start"
alignItems="center"
sx={{ height: "300vh", width: "100%", border: "2px solid white" }}
>
<Stack direction="row">
<div className="typo">
<Typography
sx={{
fontSize: "20vw",
}}
variant="h1"
>
PROJECT
</Typography>
</div>
</Stack>
<div>
<Project />
</div>
</Stack>
<Box sx={{ height: "100vh" }} />
</Container>
</main>
</div>
);
}