Hi, I'm having some issues still.
I'm doing my animations inside a useLayoutEffect but it's triggering before my fonts load from the google cdn(testing in slow 3g connection), so it starts animating with default fonts and halfway through it loads the fonts, so it looks sketchy.
Thought of just using fonts locally in my project to see if they load earlier or using a event listener but not sure how to set it up with ScrollTrigger or the correct way to do it.
const el = useRef()
const q = gsap.utils.selector(el) // Outer section
// Formatting is not great here, sorry for that
useLayoutEffect(() => {
gsap.registerPlugin(SplitText)
gsap.registerPlugin(ScrollTrigger)
ScrollTrigger.matchMedia({
// mobile
'(max-width: 639px)': function () {
},
// tablet
'(min-width: 640px) and (max-width:1279px)': function () {
},
// desktop
'(min-width: 1280px)': function () {
const intro = new SplitText(q('.header'), { type: 'chars' })
const desktopTimeline = gsap
.timeline({ defaults: { duration: 1.5, ease: 'power1' } })
.from(q, { autoalpha: 0, duration: 0 })
// rest of the timeline
}
})
return () => { ScrollTrigger.kill() }
})
Another issue I have:
I have another page that loads some card components. I want to create a effect like https://scrollrevealjs.org/ where the cards on viewport fade in and then the rest start appearing on scroll. I don't know how/where to setup the scrollTrigger, should I try to set the ScrollTrigger inside the card component so each card has its own ScrollTrigger or on the page that loads the cards? I tried the first, but didn't get it working. Want to use the MatchMedia example, so I can set different settings for each screensize.
I would also like to do this for mobile/tablet animations, because currently mi timeline executes completely even if elements are out of viewport. For desktop it's no problem but for mobile, I would prefer to use something like the scrollrevealjs example too.
I would assume all this can be done directly with the ScrollTrigger.isInViewport function
I'm looking for help with the first issue and maybe recommendations for tackling the second issue, as I want to experiment a bit more with ScrollTrigger. I've set up a basic demo of the cards page and the index page, but not sure if I can throttle the network on codesandbox for the font example. https://codesandbox.io/s/eloquent-grothendieck-zttkp?file=/pages/index.js