Jump to content
Search Community

maxWidth / minWidth being ignored on animation

fd_alistair test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

 

I don't really think it is being ignored - it is more that browsers don't work like that with regard to those properties ( width --> max-width e.g.)

 

See the Pen jOYJYOo by akapowl (@akapowl) on CodePen

 

As you can see here, while there is a max-width set on the box and thus the browser will display it at that max width set, you can still set the actual width of the box to something very high like "100000px" via JS - so it is not a GSAP related problem, you're running into. That width value will keep increasing in your example, no matter what max-width you are setting.

 

For what you are up to achieve, you will likely have to use some sort of function including clamping, like with gsap.utils.clamp

 

Now I'm not sure if tis here is the cleanest approach to that, or if it could even be made more concise using other gsap utility functions, but it does do the trick with what I understand you are up to.

 

See the Pen XWVGzvm by akapowl (@akapowl) on CodePen

 

  • Like 1
Link to comment
Share on other sites

3 minutes ago, akapowl said:

 

I don't really think it is being ignored - it is more that browsers don't work like that with regard to those properties ( width --> max-width e.g.)

 

 

 

 

As you can see here, while there is a max-width set on the box and thus the browser will display it at that max width set, you can still set the actual width of the box to something very high like "100000px" via JS - so it is not a GSAP related problem, you're running into. That width value will keep increasing in your example, no matter what max-width you are setting.

 

For what you are up to achieve, you will likely have to use some sort of function including clamping, like with gsap.utils.clamp

 

Now I'm not sure if tis here is the cleanest approach to that, or if it could even be made more concise using other gsap utility functions, but it does do the trick with what I understand you are up to.

 

 

 

 

Ok thanks! that certainly does the job.

Kinda odd this isn't a feature of GSAP?

Link to comment
Share on other sites

  • Solution
56 minutes ago, fd_alistair said:

Kinda odd this isn't a feature of GSAP?

 

No, that definitely shouldn’t be something that GSAP overrides. It’s working exactly the way it should. Otherwise, if you set width to something high and then animated the maxWidth to increase, that wouldn’t work properly.

 

I’d probably do something like this:

See the Pen YzYgeYm?editors=0010 by GreenSock (@GreenSock) on CodePen

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