I have two scrolltrigger based pins in separate React components, WorkContainer.jsx and SkillsWrapper.jsx. Both pieces of pinned content appear to jump positions on enter. The second pin, in SkillsWrapper, will also jump randomly on page refresh and will appear before or after it's pinned content section.
I've tried to remove all padding/margin to the affected sections, added context, and added "anticipatePin" to both scrolltriggers but the issue persists.
See useEffect for WorkContainer:
useEffect(() => {
let ctx = gsap.context(() => {
// Pin featured work text
ScrollTrigger.create({
trigger: '#featured-work-text',
start: 'top top',
end: 'bottom 60px',
pin: true,
// markers: true,
anticipatePin: 1,
});
const videos = gsap.utils.toArray('video');
videos.forEach(function (video) {
ScrollTrigger.create({
trigger: video,
// scroller: ".appVideos",
start: 'top 65%',
end: 'bottom 0',
// markers: true,
onEnter: () => video.play(),
onEnterBack: () => video.play(),
onLeave: () => video.pause(),
onLeaveBack: () => video.pause(),
});
});
}, component); // <- selector scoping
return () => ctx.revert();
}, []);
See useEffect for SkillsWrapper:
useEffect(() => {
let ctx = gsap.context(() => {
let mm = gsap.matchMedia();
mm.add(
{
isDesktop: '(max-width: 768px)',
isMobile: '(min-width: 768px)',
},
(context) => {
// eslint-disable-next-line no-unused-vars
let isDesktop = context.isDesktop;
// Sets Scrolltrigger pin for circle
let tl = gsap.timeline({
scrollTrigger: {
trigger: '#circle-container',
start: 'top top',
end: '+=100%',
pin: isDesktop ? false : true,
pinSpacing: false,
toggleActions: 'play none none reverse',
anticipatePin: 1,
invalidateOnRefresh: true,
// markers: true,
},
});
// ... additional commented out tl
}
);
}, component); // <- selector scoping
return () => ctx.revert();
}, []);
Please see attached video showing my issue and stackblitz links to project below:
Stackblitz project editor
Stackblitz application preview
Any help with resolving this issue would be greatly appreciated.
scrolltrigger-issues-small-2.mp4