Jump to content
Search Community

ScrollTrigger show/hide Navbar on scroll up/scroll down

lagalga test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

i don't know if this is the place to post my question, i think it's related… 

I have based on the first code to hide the header when scrolling down and it appears when scrolling up... but I also have an animation of the logo at the top of the page and I don't know how to join the 2.

The sticky header and the logo are in separate divs, although after the first animation they seem together... but I want that when a 150vh of scroll down is done, the header + logo set is hidden upwards, and that they appear again when scrolling up... all always in the area below 150vh from the top of the page...
This is what I have arrived at:

 

Orignal topic 

 

See the Pen poBmoav by lagalga (@lagalga) on CodePen

Edited by lagalga
translate to english
Link to comment
Share on other sites

  • Solution

Personally I would always create timelines in GSAP and have ScrollTrigger control the timeline you create. I've restructured your JS and give all your ScrollTrigger an ID so that when markers are on you can see when what is happening. I'm not sure if 150vh works like that in ScrollTrigger, but I personally would just the current window.innerHeight and then times 1.5 to get 150%. 

 

I’ve placed some comments in your JS to better explain things, please be sure to read through them! Hope it helps and happy tweening! 

 

See the Pen oNORgwJ?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 1
Link to comment
Share on other sites

i've just changed 150vh with :

 

const vh = (coef) => window.innerHeight * (coef/100);

start: vh(133) + ' top',

 

And it triggers well… the thing is how to hide/show the logo simultaneously with the header? If i set the same animation, the logo doesn't do the first (shrink animation)

 

Link to comment
Share on other sites

instead of animating width try setting the scale of the element, this is much more performant and has the befit that the logo is still responsive (see your demo on line 14) change width: "236px" to something like scale: 0.2, or another value that looks better. 

  • Like 2
Link to comment
Share on other sites

the thing is at start, before the animation starts, it don't resize, although the width is set to width: calc(100vw - 100px).

I do need those widths: based on width at start AND 236px at the end… making the value change with scale would involve a formula based on the width of the screen which in the end should result in a value of 236px

 

https://capture.dropbox.com/mpWJ5kxvlCb7CD2F

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