Is there any way of removing FOUC, when loading a page for the first time that has GSAP animations above the fold?
In the main hero, I have set up some animations that fire on page load.
However, when first visiting the site, you can see a very annoying FOUC with default font-family. Also, at the very first milliseconds you can see on the page all the animated items, then disappear and then re-enter with the expected GSAP animation
Am I doing something wrong? How can I prevent those FOUC?
I have used Motion.page since its release for animations, and never experience this. Now I am switching to Bricksforge and this is my first time using it for animations, so maybe I am doing something wrong
FOUC is something normal … we have it also when using plain GSAP code written in JavaScript. The solution from “Greensock” is easy to implement and will work well:
Apply visibility: hidden; to your elements in CSS and then use GSAP’s autoAlpha property to show it (or animate it in) when the page loads. autoAlpha affects opacityandvisibility , changing it to visible when the opacity is greater than 0. Pretty convenient!
So in short:
For your elements you are animating, pre-add visibility: hidden via CSS or Bricks Controls
In the Bricksforge Panel, add {autoAlpha: 1} for “to” animations or {autoAlpha: 0} for “from” animations.
The h1 and the p have animations. And those items were the ones that caused FOUC. So I added visibility:hidden to the main-hero__container, and then autoAlpha:1 on TO in the same container.
Is this something that will be ‘included’ to BF some day? Very easy to set up - but the downside is that the elements are hidden in the builder - as well.
Yep, I agree that it is annoying to have to change between visible/hidden every time I need to make a change to that section, so it becomes visible in the builder. I hope that Daniele finds a way to include this by default in BF for the above-the-fold elements, or something like this!
Hmm…I’ll think about it I can’t do that across the board, because not every animation starts with Opacity: 0. So I would have to find out when exactly this is necessary. But I love challenges