Jump to content
Search Community

keep everything within window

sunirmalya test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

i am playing with the first scrolltrigger example and want to keep everything within the window.. In particular for mobile devices etc.. When i do a fromTo it is quite happy to go off the screen..

Is there a way to keep everything within the window?

i tried setting vars as following but i couldn't get any values

var xCenter = panelsContainer.Width / 2;
var yCenter = panelsContainer.Height / 2;

See the Pen rNveOQv by sunirmalya (@sunirmalya) on CodePen

Link to comment
Share on other sites

  • Solution

If you have a specific use case `.fromTo()` is a great feature of GSAP, but I find I hardly use it, because if you position your elements correctly (with CSS) you'll just need a `.from()` tween to animate from some where to its original position. 

 

You can also lean in to view port units or use xPercent/yPercent to animate eg 100% of the elements width (that will automatically fix your tweens on every screen size) or if that is not enough you can now use gsap.matchMedia() to control your tweens on as many breakpoints as you want! 

 

 

  • Like 1
  • Thanks 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...