Jump to content
Search Community

Nav not returning to original height on window resize

ZeeEssDoubleU test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

This is a very simple example coming from a much more complex set of animations.

 

What I want seems simple, but I can't figure it out.  I'm trying to get the nav-section to return to its original height/position after the steps below are carried out.  If you follow the steps below, you'll notice the nav-section returns to a collapsed position instead of its full-height position.  This is the position delegated by styled-components, not the Timeline.

 

I'm not trying to change my styled-components or add more tweens to the Timeline.  Is there a method that clears Timeline attributes/data or one that allows CSS/styled-components to take priority over the Timeline?  Things like kill(), clear(), remove(), etc. don't seem to work in the way that I want.  Maybe I'm just using them in the wrong way.  Please advise.  Thanks.

 

Steps to recreate:

  1. Resize window (below specified px) to get nav section to stick to top
  2. Click 'Expand Nav' button to expand nav-section (full window height)
  3. Click 'Collapse Nav' button to collapse nav-section 
  4. Resize window (above specified px) to get nav section to stick back to left
  5. Notice that nav-section does not go back to original starting height specified by styled-components above {height: 100vh; width: auto}

See the Pen PoooNbZ by ZeeEssDoubleU (@ZeeEssDoubleU) on CodePen

Link to comment
Share on other sites

@OSUblake, the styles are in styled-components (css-in-js) above the component.  There's a base style and a media queried style.  That's what I'm addressing with the question. 

 

Is there a way to prevent my timeline from overriding the css/media queries or to temporarily clear the timeline so the original css kicks back in?  It's not a styled-components issue, the same issue pops up if I'm using plain css/sass/etc.

Link to comment
Share on other sites

6 minutes ago, ZeeEssDoubleU said:

Is it supposed to clear timeline props allowing an element to snap back to its original css instantly?

It clears all inline styles, so if you have the styles inline to begin with it will clear them also.

 

You should avoid inlining styles if you don't want them to be affected by GSAP :) 

  • Like 3
Link to comment
Share on other sites

37 minutes ago, ZeeEssDoubleU said:

the styles are in styled-components (css-in-js) above the component.  There's a base style and a media queried style.  That's what I'm addressing with the question. 

 

It sounds like you don't understand how inline styles work. GSAP uses inline styling to override CSS. It's a property of an element.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Using_dynamic_styling_information#DOM_Style_Object

 

Now look at how you can change stuff according to a media query watcher.

 

See the Pen WKpmxN by osublake (@osublake) on CodePen

 

 

You can remove the inline height style from your nav inside a watcher like so.

myElement.style.height = ""

// OR
TweenMax.set(myElement, {
  clearProps: "height"
});

 

But that's according to how your demo is set up.

 

I wouldn't set it up like that to begin with. There is no point in creating a timeline if it's never going to be used. 

 

 

  • Like 3
Link to comment
Share on other sites

@OSUblake,  thanks for taking the time to respond and solve the problem.  It's quite a complicated solution for a seemingly simple thing.  The media query watcher is an interesting solution.  I'll be sure to use it in the future.  Thanks again.

 

Also my mistake on misunderstanding you about inline styles.  I didn't make the connection that you were talking about my inlining of styles through the timeline.

  • Like 2
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...