Jump to content
Search Community

Can we apply "MatchMedia" to the animation in my minimum demo?

Danclp test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi there,

 

I know I have been advised to set up the timeline one section after another.

Since my ScrollTrigger animation works smoothly and well after a few tries.

I have become lazy to change the format anymore.

Anyway, there is still one small thing that I couldn't figure out, the MatchMedia.

Is it possible that we can insert the MatchMedia command line in between the timeline?

If the answer is yes, I wonder how does it work?

Through the research, I had no luck getting similar references (or maybe I didn't search properly).

As you can see in the attached screenshot, I intend to keep the content centred on the desktop mode and be able to scroll through the screen while on mobile.

However, with my current code, how do I implement MatchMedia though?

Can someone kindly give me some guidance?

Thank you.

 

.fromTo(".section-4 .text", {
    xPercent: 100,
  }, {
    xPercent: 0,
    duration: 1
  }, "<")
  .to(".section-4", {
    autoAlpha: 0
  })
  .to(".section-5", {
    autoAlpha: 1,
    duration: 1
  })
// MatchMedia condition to be applied here?
  .fromTo(".section-wrap", {
    yPercent: 0
  }, {
    yPercent: -85,
    duration: 2
  }, "<+=0.5")
// End here
  .to(".section-5", {
    autoAlpha: 0,
    delay: 5,
    duration: 1
  })

 

SCR-20230725-wmp.thumb.png.7bb8a8e7b88e99493a17944c19706710.png

See the Pen mdQGLLO by danclp (@danclp) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

It can be done but it would create an unexpected result, the reason being that MatchMedia will take care of reverting everything that is created within it's scope and run the animation when the breakpoint is passed, but if you add animations outside that scope only the animation within the scope will run and the other will stay in the state they are at that point.

 

Here is a simple example that illustrates how this behaves:

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

 

If that is what you are looking for as a result, then go ahead. My advice will be to always put everything inside the MatchMedia instance in order to correctly revert and avoid odd visual glitches or situations like this, but you'll have to decide what's the best outcome for your project.

 

Hopefully this helps.

Happy Tweening!

  • Like 2
Link to comment
Share on other sites

Hi Rodrigo,

 

Once again, thanks for the reply.

I will give this suggestion a try.

However, if this is not the best practice, in my case, putting everything inside the MatchMedia instance may not work either.

 

"Section 5" is the only section I have problems with on different devices.

Do you have any other recommendations that you could provide me with?

I hope I am not taking things for granted, as I am the only brain on this development.

So, suggestions are pretty much appreciated.

Link to comment
Share on other sites

Hi,

 

I wouldn't categorize this as best practices territory. There is nothing inherently wrong with the approach you want to take, just a visual issue that would depend on the setup you have.

 

In your demo you don't have a GSAP MatchMedia instance so we can't see what could be the issue there. So it would be great if you could include a minimal demo that shows exactly what you're trying to do and what is not working, there is not much we can do.

 

Happy Tweening!

Link to comment
Share on other sites

Hi Rodrigo,

 

Understand.

I was just trying my luck to see if there are any other possible answers.

Anyhow, the earlier suggested method works perfectly fine with my codes.

Once again, thanks a million for your patience.

Have a great day.

 

Link to comment
Share on other sites

Hi,

 

There could be other options but those would imply more sophisticated custom logic, like using labels and replaying the timeline from a certain point based on the breakpoint, etc. But that's a bit beyond the help we can provide in these free forums, since it would be tied to design and UI/UX decisions among other things, which falls into the consulting category.

 

The main idea in the current thread is for you and other users to know the basic behaviour and how to go from there.

 

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

47 minutes ago, Danclp said:

I am a designer and a self-trained web developer.

Ha! Same here! Just hang around these forums and when you feel like it try to help others, that's the way I've learned and still am learning! 

 

Your project is looking good, don't sweat it to much, if it works it works. Good luck and happy tweening! 

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