Jump to content
Search Community

[Violation] Forced reflow while executing JavaScript took 43ms

Delphine test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hello,
I need to deliver a wordpress website that I developed locally, and I have one last issue to resolve: when any page on the site loads, I encounter an error: "[Violation] Forced reflow while executing JavaScript took 43ms."

Thanks to this stackoverflow page, I've identified the piece of code that appears to be causing this reflow, which you can see in the CodePen.

I've tried to change my code multiple times, but nothing seems to work!
I've been struggling with this issue for two days now, and I'm starting to despair.

Could you please assist me in resolving this reflow issue?

Many thanks for your help !
 

 

See the Pen bGOQPdd by afine1170 (@afine1170) on CodePen

Link to comment
Share on other sites

Hello, 

Sorry, I continued searching for the solution and modified my CodePen code in the meantime!

Here is the code that was causing the problem:

 

gsap.registerEffect({
  name: "fade",
  defaults: {
    scale: 0,
    opacity: 0,
    duration: 5,
},
  effect: (targets, config) => {
    return gsap.fromTo(targets, {
        scale: config.scale,
        opacity: config.opacity,
        duration: config.duration,
        transformOrigin: 'center center',
        x: 'random(-500,500)',
        y: 'random(-500,500)',
    }, {
       scale: 1,
       opacity: 1,
       duration: config.duration,
       x: 0,
       y: 0,
    });
  }
  });

  const mots = document.querySelectorAll('.b4-nuage-de-mots li');

 gsap.from(mots, {
    duration: 'random(1, 5)',
	scrollTrigger: '.b4-nuage-de-mots',
	transformOrigin: 'center center',
    scale: 0,
    opacity: 0,
    x: 'random(-100,100)',
    y: 'random(-100,100)',
    delay: .8,
 });

    mots.forEach((mot) => {
                mot.style.willChange = 'transform, opacity';
                gsap.from(mot, {
                    duration: 'random(1, 5)',
                    scrollTrigger: '.b4-nuage-de-mots',
                    scale: 0,
                    opacity: 0,
                    x: 'random(-100,100)',
                    y: 'random(-100,100)',
                    delay: .8,
                });
                gsap.fromTo(mot, {
                    scale: 0,
                    opacity: 0,
                    duration: 5,
                    x: 'random(-500,500)',
                    y: 'random(-500,500)',
                }, {
                    scale: 1,
                    opacity: 1,
                    duration: 5,
                    x: 0,
                    y: 0,
                })
         });
         mot.addEventListener('mouseenter', () => {
			gsap.effects.fade(mot, {
			duration: 'random(3, 6)',
		});
	});

});

Unfortunately, I still have a reflow problem. I'm still searching to identify which part...


Thanks for you answer.

Link to comment
Share on other sites

That's because you set up several animations to run first, and THEN you were calling the function that ran the .from() which rendered those elements the proper way. I'm not sure why you put that in an onComplete to run in sequence instead of just dropping it into the parent timeline directly so that the function runs right away: 

See the Pen yLGGQKb?editors=0110 by GreenSock (@GreenSock) on CodePen

 

Also, you could set the initial state of things in CSS and then use a .to() instead of a .from() to avoid the "FOUC"

  • Thanks 1
Link to comment
Share on other sites

Quote

Also, you could set the initial state of things in CSS and then use a .to() instead of a .from() to avoid the "FOUC"

How could I know that my problem was called FOUC!!!! 
Everything lights up! But I have to review all my copy now!!!
Many thanks GreenSock superhero!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...