Hi @Rodrigo!
Thank you for the fast reply and the workaround!
It actually helped, however I went further and tried to test it in different real-world scenarios, so had a chance to make it a bit more bullet-proof.
Here's the updated version with the fix:
https://codepen.io/idudinov/pen/VwVWOry
And sharing the steps I've came up with based on my experience.
Just after the dynamic ScrollTrigger with a pin has been created, do the following:
call ScrollTrigger.refresh()- it's required if the new ST has scrub animation, otherwise its 'start'/'end' might be undefined;
next it's needed to calculate where the page current scroll should actually be at this moment. For my case, I rely on the parent ST – taking its trigger and start/end configuration
determine where from you're approaching the ST – whether 'start' or 'end'. I decided to check current ST's progress like that: progress < 0.5 ? 'start' : 'end'. such approach makes sense when scroll position can be reset by navigation, like we're teleporting from the lowest section to the top of the first one – in this case we'll receive 'onEnterBack' from ST, however visually we're at the top.
then take parent's ST 'start' or 'end' configuration according to previous step, not in pixels but as string like 'bottom top', we name it targetPosition
use it to calculate actual offset via currentScrollSmoother.offset(parentScrollTrigger.trigger, targetPosition) – that gives you final scroll position you need
it's important to add some extra offset (1 or 2 px is enough) to the targetPosition towards the direction (+ or -) to make sure your parent and nested trigger will remain in the trigger area.
set the scroll position instantly via currentScrollSmoother.scrollTop()
and finally refresh your smoother like that: currentScrollSmoother.scrollTrigger.refresh()
Important to make sure that the smoother is currently not being affected by some another scrollTops etc.
I was testing all this on Mac in Chrome, Safari and Firefox. I'll try to keep this thread up to date if I find something some other interesting details.