Jump to content
Search Community

Window resize break layout bug

Samuele test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

Hi there!
I'm approaching GSAP during these week and I have noticed something odd that affects the layout when the screen is resized (responsive mode)
I've already set all the value to percentage in the js file, and so in .vh for the css margin.

I think that a solution could be refresh the element position once resized a page
Considered all the device (IOS UI bar)

Link to comment
Share on other sites

Can you please elaborate a bit? I don't know what images aren't being aligned in the way you're expecting. 

 

Keep in mind that iOS Safari resizes the window when the user scrolls up or down because it shows/hides the browser chrome. In order to avoid a sudden stop to the momentum-scrolling, ScrollTrigger defers its refresh() until the scroll has stopped. That's when you'll see ScrollTrigger update its positions. 

Link to comment
Share on other sites

2 hours ago, GreenSock said:

Keep in mind that iOS Safari resizes the window when the user scrolls up or down because it shows/hides the browser chrome.

That's what I'm trying to resolve. 
For every images that has a transition effect passed by GSAP, in IOS Safari will be not aligned properly due the browser chrome. (as you can see there is a white space under the bar)

I'm looking for a solution like refreshing the animation on window resize or something like that... would be that possibile?

Schermata 2021-06-04 alle 09.48.42.png

Link to comment
Share on other sites

Thanks for the feedback!

So to update my value I need to use a function, but would be something like that:

 

ScrollTrigger.refresh();
y: (refresh) => -height / 2.5

(I'm sorry but I will eventually need some lessons of javascript)

Link to comment
Share on other sites

10 hours ago, Samuele said:

So to update my value I need to use a function, but would be something like that:

 

ScrollTrigger.refresh();
y: (refresh) => -height / 2.5

I don't quite understand your question. Can you elaborate a bit? Perhaps it'd be best if you provided a minimal demo please instead of a small excerpt of the code without any context. 

Link to comment
Share on other sites

On 6/4/2021 at 5:37 PM, OSUblake said:

ScrollTrigger does refresh on resize. To grab your updated values, you need to use a function.


Yeah I'm uploading my Codepen, but I didn't understand how do I insert a function in order to grab the updated values on resize...

Link to comment
Share on other sites

Ok maybe I figured out what is causing trouble.

See the Pen RwpxPKb by sml-k (@sml-k) on CodePen


 

On 6/4/2021 at 5:37 PM, OSUblake said:

Also, 100vh might not be what you want on mobile.

This trick works very fine but when I use a margin-top it actually doesn't aligned properly (please see the previous comment).
Basically I used margin top in css combined with an opposite transition value in gsap.

IE: move "mydiv" of y: 100px, and then in css "mydiv" margin-top: -100px (this allows me to aligned an element in his original position when scrolled)

Link to comment
Share on other sites

  • Solution

See the Pen 8a2b93488881f6b89f6c82d8b4eac40c by cassie-codes (@cassie-codes) on CodePen



I'm not sure exactly what you're trying to do here - your demo has quite a lot going on. But here's a little demo of a tween with a functional value and the invalidateOnRefresh property.

I've added a listener to update the width variable too, hope this helps?

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