Dovisally Posted May 11, 2020 Share Posted May 11, 2020 Hello, I have a block over a text and i want to reveal the text and make the width of the block zero as far as i know it is bad for performance to animate width, and since i'm gonna use this animation quite a lot i'm worried to animate width so is there is any better solution for my little problem ? also can i change the animation direction from right > left to left > right ? See the Pen LYpmKJb by dovisally (@dovisally) on CodePen Link to comment Share on other sites More sharing options...
mikel Posted May 11, 2020 Share Posted May 11, 2020 Hey @Dovisally, You could use scaleX and transformOrigin ... See the Pen WNQJVJb by mikeK (@mikeK) on CodePen Happy tweening Mikel 4 Link to comment Share on other sites More sharing options...
Dovisally Posted May 11, 2020 Author Share Posted May 11, 2020 Thank you so much Mikel ❤️ one more question if you don't mind, i can't get it to work with intersection observer just wanted to know what i'm doing wrong ? i'm not getting any errors in the console so i assume it's not a typo const targets = document.querySelectorAll('.block'); const blockReveal = target => { const io = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if(entry.isIntersecting) { const block = entry.target; gsap.to(block, { scaleX: 0, ease: Power4.easeIn, stagger: 0.1,}, 0.1); observer.disconnect(); } }); }); io.observe(target); }; targets.forEach(blockReveal); Link to comment Share on other sites More sharing options...
ZachSaucier Posted May 11, 2020 Share Posted May 11, 2020 27 minutes ago, Dovisally said: i can't get it to work with intersection observer just wanted to know what i'm doing wrong ? A few notes: I'd create just one intersection observer and observe all of your elements using it. Then instead of observer.disconnect I'd use .unobserve. You have 0.1 in the stagger, but there's just one element so it's not going to have an effect. You have 0.1 in the position parameter but it's not a timeline tween so that's invalid. For more info, see our page on the position parameter. Based on just the code you provide I would think that it would animate once the element starts being visible. The only time when it wouldn't is if your elements start inside of the window and never are scrolled out of the window. Can you please create a minimal demo exemplifying the issue? 1 Link to comment Share on other sites More sharing options...
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