I've been experimenting with GSAP for the past few weeks using next, and I've been trying to use "pin" with "scrollTrigger." However, it seems like I'm getting extra white space every time I use "pin" with the scroll trigger. Is there something wrong with my code?
first, I create two refs.
const animatedPath = useRef(null)
const svgref = useRef(null)
and second I use `useLayoutEffect` for register scroll trigger plugin and define gasp animation
useLayoutEffect(() => {
gsap.registerPlugin(ScrollTrigger)
const tl = gsap.timeline({
scrollTrigger: {
trigger: svgref.current,
start: "top top",
end: "bottom 100",
scrub: true,
markers: true,
pin: true
}
})
gsap.set(animatedPath.current, {
strokeDasharray: 471.2,
strokeDashoffset: 471.2,
})
tl.to(animatedPath.current, {
strokeDashoffset: 0
})
}, [])
after that, i create svg with circle inside it
<section style={{ height: "200vh" }}>
<svg ref={svgref} style={{ width: "400px", height: "400px" }} xmlns="http://www.w3.org/2000/svg">
<circle cx={200} cy={200} r={75} fill="none" stroke="black" strokeWidth={10} ref={animatedPath} />
</svg>
</section>
The result shows that the `pin-spacer` class has a large padding/whitespace, and the animation doesn't start properly.
full link https://codesandbox.io/p/sandbox/sad-lalande-q7c578?file=%2Fapp%2Fglobals.css%3A1%2C1
Thanks in advance!