Nicolassz Posted November 3, 2022 Share Posted November 3, 2022 Hey guys, i'm trying to animate a hidden section, which appears when you press a button in the main section. The result i want to achieve is similar to this site: https://clock-app-frontendmentor.vercel.app/ When you click the "more" button, it animate the main section, throwing it up and appearing the "more info" section. What do i have to use from gsap to achieve that? I tried the FLIP Plugin but i wasn't able to make it work, idk how it works well... BTW, i'm using React + TailwindCSS Here is what i tried to do with Flip: const infoContainer = Flip.getState(".infoContainer"); const clockContainer = Flip.getState(".clockContainer"); Flip.from(infoContainer, { duration: 1, ease: "power3.inOut", targets: ".infoContainer", scale: true, absolute: true, onEnter: (elements) => gsap.fromTo( elements, { translateY: 2 }, { translateY: 0, opacity: 1, duration: 1 } ), onLeave: (elements) => gsap.to(elements, { opacity: 0, duration: 1 }), }); Flip.from(clockContainer, { absolute: true, scale: true, duration: 1, ease: "power3.inOut", }); And here are the clockContainer and the infoContainer, only the sections... Clock Container: <section className="clockContainer flex items-end justify-between text-almostWhite"></section> Info Container: <section className={` ${openInfo ? "translate-y-0" : "hidden translate-y-full"} infoContainer flex h-3/4 w-full items-center bg-white/70 backdrop-blur-md`} > If you need any more information, please let me know! Thanks Codesandbox Link: https://codesandbox.io/s/clock-app-ewji38?file=/src/App.tsx Link to comment Share on other sites More sharing options...
GSAP Helper Posted November 3, 2022 Share Posted November 3, 2022 It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer. Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. Link to comment Share on other sites More sharing options...
Nicolassz Posted November 3, 2022 Author Share Posted November 3, 2022 Sure @GSAP Helper! Here is the codesandbox of my project. (All stuffs are running at App.tsx) https://codesandbox.io/s/clock-app-ewji38?file=/src/App.tsx Link to comment Share on other sites More sharing options...
Solution Rodrigo Posted November 3, 2022 Solution Share Posted November 3, 2022 Hi @Nicolassz and welcome to the GreenSock forums! IMHO I don't think you need Flip for this. You have two elements with heights based on the screen height, so all you have to do is tinker a bit with the CSS, positions, opacity and add a GSAP set instance in the first run and create a single timeline that animates everything using responsive transform values: useLayoutEffect(() => { const ctx = gsap.context(() => { gsap.set(".infoContainer", { yPercent: 100, opacity: 1 }); tl.current = gsap .timeline({ paused: true, defaults: { ease: "power2.inOut", }, }) .to(".infoContainer", { yPercent: 0 }) .to(".clockContainer", { y: "-40vh" }, "<") .to(".quotes", { y: -100, opacity: 0 }, "<") .reverse(); }, app); return () => ctx.revert(); }, []); useLayoutEffect(() => { tl.current.reversed(!openInfo); }, [openInfo]); Here is a fork of your example that shows how it works: https://codesandbox.io/s/clock-app-forked-s24j9u?file=/src/App.tsx:572-1152 Let us know if you have more questions. Happy Tweening! 1 1 Link to comment Share on other sites More sharing options...
Nicolassz Posted November 4, 2022 Author Share Posted November 4, 2022 Thanks @Rodrigo, that was exactly what i was looking for!! I'm gonna search more about this gsap context and yPercent etc... Have a great rest of your week 😃 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