Jump to content
Search Community

Stagger for child html tag of main element

Quang Anh test
Moderator Tag

Recommended Posts

Hi. I would like know if you can use Stagger to trigger gsap function of the main html element. To make it more clear, here is my example:

<div class="home-work-image-list-top">
        <a href="#" class="wrapper-top">
          <figure class="holder">
            <img src="/img/work/dis_list-architectural-design.jpg" alt="">
          </figure>
        </a>
        <a href="#" class="wrapper-top">
          <figure class="holder">
            <img src="/img/work/dis_list-branding.jpg" alt="">
          </figure>
        </a>
        <a href="#" class="wrapper-top">
          <figure class="holder">
            <img src="/img/work/dis_list-furniture-production.jpg" alt="">
          </figure>
        </a>
</div>
<script>
gsap.from('.home-work-image-list-top .wrapper-top', {
   y: '+=400',
   duration:0.5, ease:'power2.out',
   stagger: [
   // Use the gsap that trigger the child tag of .wrapper-top, everytime .wrapper-top called out by stagger like this
     gsap.timeline()
     .fromTo(".home-work-image-list-top .wrapper-top .holder", {xPercent:-100}, {duration: 3, xPercent:0})
     .fromTo(".home-work-image-list-top .wrapper-top .holder img", {xPercent:100}, {duration: 3, xPercent: 0}, "<");
   // End
   ]
 },1)           
</script>

I know the code above wouldn't work ubt that just a way I want it to run. If anyone can solve my math I would be apreciate.

  • Like 1
Link to comment
Share on other sites

Sorry for late responding. I will explain more clear: I have watch the documents about stagger and understand a little bit. As you can see in my html, I have a list of class wrapper-top, I'm using stagger to trigger animation for ".wrapper-top" in order instead of all at once. I also want to trigger animation of its .holder and img (which inside .wrapper-top) in order too but instead they run all at once. So I want to know trigger the child tag of .wrapper-top, every time .wrapper-top called out by stagger? I'm new to gsap so I'm missing something please let me know.

Link to comment
Share on other sites

Perhaps you're looking for something like this?:

let stagger = 0.5;
gsap.utils.toArray('.home-work-image-list-top .wrapper-top').forEach((wrapper, i) => {
  let tl = gsap.timeline({delay: i * stagger});
  tl.from(wrapper, {y: '+=400', duration: 0.5, ease: 'power2'})
    .fromTo(wrapper.querySelector(".holder"), {xPercent:-100}, {duration: 3, xPercent:0})
    .fromTo(wrapper.querySelector(".holder img"), {xPercent: 100}, {duration: 3, xPercent: 0}, "<");
});

If you still need help, please provide a minimal demo (like a CodePen) for quick editing.

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