Jump to content
Search Community

Problem with looping multiple sections

D1MK4 test
Moderator Tag

Recommended Posts

Hello, I've got a problem with animations.

I'm trying to animate multiple sections and elements inside with the stagger.

I wrote a code like this:

 

 

And animation looks very good, every item in the section is animating with a stagger, generally everything is fine until I add the same section (.products-grid) below existing section in html.

Two same sections on the same site are causing a bug and the animation is not working. (It is starting but looks like it's stopping at 10% maybe).

To be honest I searched a lot of topics and tried to fix this but I'm in a dead end.

Can anyone look at this and maybe try to help me even a little bit?

Greetings.

See the Pen ZEKPMBB by D1MK4 (@D1MK4) on CodePen

Link to comment
Share on other sites

Like Blake said, it's very difficult to troubleshoot by only looking at the JS, but my guess is that you're looking for something like this: 

const productsGrids = gsap.utils.toArray(".products-grid");

productsGrids.forEach((productsGrid) => {
	gsap.from(productsGrid.querySelectorAll(".products-listing .single-product"), {
		scrollTrigger: {
			trigger: productsGrid,
			start: "-50px 80%",
		},
		opacity: 0,
		y: 300,
		duration: 0.4,
		stagger: 0.15,
	});
});

If you need more help, please add HTML/CSS to that CodePen demo so we can see things in the proper context. 

 

Happy tweening!

Link to comment
Share on other sites

6 minutes ago, GreenSock said:

Like Blake said, it's very difficult to troubleshoot by only looking at the JS, but my guess is that you're looking for something like this: 


const productsGrids = gsap.utils.toArray(".products-grid");

productsGrids.forEach((productsGrid) => {
	gsap.from(productsGrid.querySelector(".products-listing .single-product"), {
		scrollTrigger: {
			trigger: productsGrid,
			start: "-50px 80%",
		},
		opacity: 0,
		y: 300,
		duration: 0.4,
		stagger: 0.15,
	});
});

If you need more help, please add HTML/CSS to that CodePen demo so we can see things in the proper context. 

 

Happy tweening!

 

I've added HTML and CSS, thank you

Link to comment
Share on other sites

Thanks for the demo, it's very helpful.

 

Jack's code is probably what you're after, but with a little change.

 

// this selects the first product
productsGrid.querySelector(".products-listing .single-product")

// this selects all the products
productsGrid.querySelectorAll(".products-listing .single-product")

 

  • Like 1
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...