Jump to content


Changing .to width based on media query

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts



I have an element that is set in the CSS to 100% to start and then animates to a smaller width.


I need this width to be different if the screen is smaller so I'm using a $(window).width in JavaScript to pass the desired destination width to TimelineMax.


This works but I need this width to respond to changes in window width.


Using $(window).resize() to try and change these widths again in the JavaScript seems overkill. Can anyone offer a more elegant solution?


I can't use .from because that element must be 100% when the page loads, and I can't circumvent the delay before the JS kicks in (as far as I know).


Change the browser width before you run the Codepen to see the difference.



See the Pen ZGWVwe by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi mikeebee  :)


you can handle that with javascript media queries , and i think that's better to tween width with percent value


maybe this can help you : 







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