Jump to content
Search Community

Flip in images multiple delays needed

kodralex test
Moderator Tag

Go to solution Solved by alig01,

Recommended Posts

Hi,

 

So I have some images that are flipping in when you scroll down the page. This all works fine. But I would like to delay some of the images so they don't all flip in at the same time. In my CodePen demo, there are only three images; in my development site, there may be 20/30+ images. So I need an easy(ish) solution. Could I maybe add a data-delay attribute to the element div and set a delay amount this way? Anyone got any ideas on the best way for me to approach this?

 

Thanks,

Alex

See the Pen LYgjOdW by alexkodr (@alexkodr) on CodePen

Link to comment
Share on other sites

  • Solution

Hey, the easiest solution would be to use stagger. It works like an offset for the starting time of each element. 

Check out the docs there is an interactive demo that can show you the possibilities.

 

See the Pen jOeLYWE?editors=0010 by alig01 (@alig01) on CodePen

 

Also no need to use fromTo, if you want to get to the initial position. And I added to your .element class visibility: hidden in the css to avoid fouc.

 

Hope this helps and good luck with your project.

  • Like 4
Link to comment
Share on other sites

Hi all,

 

Just coming back to this one. I've come across a few further bits I need help with. So In my updated CodePen, I have multiple images that are being animated. Each set of images is inside its own .container div, which is the trigger. But I will have many of these on the page. After a little reading around, it would seem I use something like this

 

gsap.utils.toArray(".container").forEach((container) => {

But it's not behaving how I want it. What am I missing here?

 

The next issue is with the animation itself. I'm trying to mimic the animation on the panels on this page: https://www.playmakerstudio.com/lifestyle/. The panel has a slight verticle flip when coming onto the page (it's not distorted). I've tried to reproduce this using perspective (see my CodePen). But I can see this isn't exactly right. On my GSAP version, the images are distorted. I think they should be rotated slightly on an axis rather than a perspective shift. Has anyone got any ideas?

Link to comment
Share on other sites

Hi,

 

The problem is just a selector logic issue. Right now you have this on your loop:

gsap.from(".element",  {
  scrollTrigger: {
    trigger: container,
    scrub: 1,
    start: "top center",
    end: "bottom bottom",
    markers: true
  },
  //autoAlpha: 0,
  rotationX: -10,
  stagger: {
    grid: [3, 3],
    from: "random",
    amount: 1.5
  }
});

So basically for every container you're selecting all the DOM nodes with the class ".element" from every container. What you need to do is target the nodes with that class that are children of the specific container:

gsap.utils.toArray(".container").forEach((container) => {
  const elements = container.querySelectorAll(".element");
  gsap.from(elements, {
    scrollTrigger: {
      trigger: container,
      scrub: 1,
      start: "top center",
      end: "bottom bottom",
      markers: true
    },
    //autoAlpha: 0,
    rotationX: -10,
    stagger: {
      grid: [1, 3],
      from: "random",
      amount: 1.5
    }
  });
});

Here is a fork of your codepen:

See the Pen xxyXVeo by GreenSock (@GreenSock) on CodePen

 

Happy Tweening!

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