Jump to content
Search Community

animations from 100% height not work

jonForum test
Moderator Tag

Recommended Posts

Am getting a issue here 

return (
	<Box
		display='flex'
		flexDirection='column'
	>
		<Box display='flex'>
			<Button
				onClick={() => {
					lstore.open = !lstore.open;
					const domNode = lstore.collabeRef.current;
					const h = lstore.open ? domNode.scrollHeight : 0;
					if (lstore.open) {
						// if proceed opening
						gsap.to(domNode, 0.3, { height: h, opacity: 1 })
						.eventCallback('onComplete', () => {
							domNode.style.height = '100%';
						});
					} else {
                      // here the issue, if node have with 100% , animations not work
                      // i also try From and domNode.style.height = domNode.scrollHeight+'px' not work
						gsap.to(domNode, 0.3, { height: 0, opacity: 0 });
					}
					gsap.fromTo(domNode, 0.5, { translateX: -100 }, { translateX: 0 });
				}}
			>
				{title}
			</Button>
		</Box>
		<Box
			ref={lstore.collabeRef}
		>
			{children}
		</Box>
	</Box>
);

after the event onComplete fired 

the following code `gsap.to(domNode, 0.3, { height: 0, opacity: 0 });`  no longer works and there are no more animations.

 

how i can animate height 100% to 0% or 0px ?

i also try hacky way like just before perform this 
domNode.style.height = domNode.scrollHeight+'px'

just before the animations , but not work ! 

thanks

Link to comment
Share on other sites

Hey jon. As covered in my article about animating efficiently, we recommend that you create the animation outside of the click event listener and then just use control methods inside of the click event listener. This not only is more performant but also prevents you from having logical issues :) 

 

If you'd like additional help debugging please make a minimal demo of the issue.

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