Jump to content
Search Community

ScrollTo: How to scroll to div in center of viewport

elschnuppero test
Moderator Tag

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

Here's some pseudocode to center something.

var x = (viewWidth - targetWidth) / 2;
var y = (viewHeight - targetHeight) / 2;

 

So calculate the x, and use that as the offset in your tween.

TweenMax.to(window, 2, {scrollTo:{x:"#target", offsetX: someCalculation }});

 

Anything more complicated than that and you'll probably need to build your own camera system.

  • Like 6
Link to comment
Share on other sites

1 hour ago, OSUblake said:

Here's some pseudocode to center something.


var x = (viewWidth - targetWidth) / 2;
var y = (viewHeight - targetHeight) / 2;

 

So calculate the x, and use that as the offset in your tween.


TweenMax.to(window, 2, {scrollTo:{x:"#target", offsetX: someCalculation }});

 

Anything more complicated than that and you'll probably need to build your own camera system.

 

Awesome. The offsetX was exactly what i was looking for. Thank you.

 

Side question: Is there somewhere something like a cheatsheet where i can find all possible parameters? I know the cheatsheet from ihatetomatoes but is there something similar in more detail?

Link to comment
Share on other sites

44 minutes ago, elschnuppero said:

Side question: Is there somewhere something like a cheatsheet where i can find all possible parameters? I know the cheatsheet from ihatetomatoes but is there something similar in more detail?

 

That cheatsheet is probably the best source at the moment. I think some new docs are in the works, and when I get around to creating a new set of typescript definitions, you can generate docs that will show all the parameters for plugins.

  • Like 2
Link to comment
Share on other sites

3 hours ago, OSUblake said:

 

... and when I get around to creating a new set of typescript definitions, you can generate docs that will show all the parameters for plugins.

 

Well, i dont have any idea what this part means, but the other stuff was very helpful :-D. Thanks a lot.

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