Hi,
In the SrollTrigger config is markers (plural) not marker:
// Wrong
scrollTrigger: {
marker: true,
},
// Right
scrollTrigger: {
markers: true,
},
Also once again you're making the same mistake. Sooner or later this will become a logical issue:
const menuTimeline = gsap.timeline({
scrollTrigger: {
trigger: "#pin-container-2",
pin: "#pin-container-2",
pinnedContainer: "#pin-container-2",
start: "top top",
// YOU HAVE SCRUB HERE
scrub: true,
markers: { indent: 140 },
id: "menu"
}
});
Then you have this:
function selectEgg() {
menuTimeline.reverse();
}
function selectFish() {
menuTimeline.reverse();
}
Your menu timeline's playhead position is controlled by the scroll position when using scrub, then you want to reverse it using a button, which can be done, but as soon as the user scrolls ScrollTrigger will update the same timeline's playhead position based on the scroll position which will make the menu elements visible again and behave in an erratic fashion. You cannot have a scrubbed animation play/reverse using other event handlers unless you remove the ScrollTrigger instance associated with it, in which case you no longer will be able to scrub that GSAP instance.
IMHO it should be like this:
const menuTimeline = gsap.timeline({
scrollTrigger: {
trigger: "#pin-container-2",
pin: "#pin-container-2",
pinnedContainer: "#pin-container-2",
start: "top top",
toggleActions: "play none none reverse",
markers: { indent: 140 },
id: "menu"
}
});
Finally I think this is not a good approach as well:
function selectEgg() {
menuTimeline.reverse();
const eggTimeline = gsap.timeline({
scrollTrigger: {
trigger: "#pin-container-2",
pin: "#pin-container-2",
pinnedContainer: "#pin-container-2",
start: "top top",
scrub: true,
markers: { indent: 300 },
id: "btn"
}
});
eggTimeline
.to("#besteck-2", { display: "block", x: "-20vw" })
.to("#egg-dish", { display: "block", x: "-60vw" });
}
I wouldn't create a GSAP instance controlled by ScrollTrigger on an event handler. What happens if the user opens the menu and clicks on that button again? The same instance will be created again, but the previous one is already there and the same element is already pinned.
Finally I think you are overcomplicating this quite a bit and because of that your app has several logic and architectural issues. I think the best approach right now is to decide what exactly you want to do and start by creating an HTML and CSS structure that looks the way you want. Then start adding animations one by one, go section by section and then also start adding complexity to this. It seems to me that you are a bit over your head right now, so that's why going back to basics should be a solid first step.
Hopefully this helps.
Happy Tweening!