Adam.shires Posted May 19, 2023 Posted May 19, 2023 Hey Everyone, Been scrathcing my head over this one and simply can't figure out how to implement ScrollTrigger rfresh(); to recalculate % start and end values on screen resize. So in my demo there are two elements which on scroll reduce their widths from 50% - 0% in the left and right direction, Imagine two curtains opening. Upon load, and with screen resize the two curtains both take up 50% of the viewport no problem, but if I resize after engaging the scrollTrigger the intial values of the 50% are remaining and the "curtains" overlap each other. As can be seen when scrolling and then resizing in the demo. I believed this to be a simple fix with ScrollTrigger.refresh(); to recalculate but I feel like I'm missing something super obvious! Sorry for the silly question I've been wracking my head over this one and have been staring at the screen for hours lol ? See the Pen OJBaJKE by Geeza82 (@Geeza82) on CodePen.
Solution Rodrigo Posted May 19, 2023 Solution Posted May 19, 2023 Hi, This is basically related to the units you're passing to GSAP. So right now you're passing a number 0, so GSAP says: "OK, you want me to tween the width of this element to 0 pixels" and GSAP, being an extremely good library, does exactly what you're asking. The problem is that you're basing your entire setup in percentage-based values. For that you have to be specific so GSAP knows you're intentions. Regardless of all the hard work putted into GSAP, the library still can't read minds . This seems to work the way you intend: walltl .to(".left-crunch", { width: "0%" }) .to(".right-crunch", { width: "0%" }, 0); Hopefully this helps. Happy Tweening! 3 1
Adam.shires Posted May 22, 2023 Author Posted May 22, 2023 Oh my! lol I feel like a dope hahaha. Amazing how the simplest things can get lost when you've been staring at the screen for soooo long Thanks So much @Rodrigo Legend 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now