Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jonForum

animations from 100% height not work

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 post
Share on other sites

756zTQ5D_o.gif

here the behavior, first collapse pass work , but after no animation.

it might sound silly, but i'm a bit obsessive about this detail, even if it's still functional for the app !.

Link to post
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 post
Share on other sites
46 minutes ago, ZachSaucier said:

 

 

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

sure , did you have template with https://codesandbox.io/ with gsap and react , just for save time, or i can do one.
Will take a look on your article, thanks.

Link to post
Share on other sites

The video in this post covers how to create one (start at 4:34 for the CodeSandbox part):

 

  • Thanks 1
Link to post
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.

×