Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How can I get this animation in WordPress?

Is it possible to recreate the navigation animation from this site:

gensler.com

I’d like to have the animation that shows the navigation area adjusting when you scroll down the page. I like how the menu items shift up and resize as a smooth animation.

Are there any plugins like this or would it have to be done as it’s own little project?

I'm new to js so if I do have to make this on my own what should I be searching for to find a tutorial? Transitions? Animations? Something else?

Thanks!

5 Answers

You can use jQuery to recognize when scrolling has occurred, then style the navigation element accordingly.

Here is an example: http://stackoverflow.com/questions/11434735/change-element-style-on-page-scroll

Thanks, Kris!

Here's a demo I'm using to try to figure this out: http://codepen.io/mrhines1/pen/KwpRop?editors=011

It's from a tutorial here on Treehouse. I modified it so that the nav bar height transitions from 80px to 50px when the page scrolls past a certain point. Also, I have the font-size transition from 0.9em to 0.8em.

So far everything looks good when the nav area transitions down. But when the page is scrolled back up and the nav bar needs to go back to it's original size there is an abrupt jump in the animation. It's not smooth like it is when it minimizes. It looks as though the main contents padding is affected by the change in the nav bar's height.

Any ideas? Am I targeting the wrong class with the transitions?

You have this in the CSS:

.main-nav,
.main {
  position: relative; 
}

Try this instead:

.main-nav {
  position: relative; 
}

.main {
  position: absolute;
}

I tried it with the change in the CSS and I'm still seeing the main content "jump" when the nav bar increases back to 80px.

Make sure you do a hard refresh on the page:

Windows: CTRL+F5 Mac: CMD + SHIFT + R

I made the change in CodePen and it was working properly.

Thanks again, Kris!

I made a new pen: http://codepen.io/mrhines1/pen/wBKWMd

It's the same idea as the first one, except that I have moved the nav bar to the top of the screen right from the beginning. However, now I am not getting any of the transitions to work. I would still like the nav bar to minimize like it does in the other pen. The only JS code I have modified is changing "hdr" to an exact measurement of "10px" since the height of the header no longer comes into play.

Again, I'm new to JS so I'm not sure what I'm missing here.

On this one, you forget to tell CodePen that you're using jQuery :-)

Ha! That's great!

I updated the pen to include the jQuery library but I'm not seeing the script have any effect on the page. I did a refresh of the page. I'm still not getting the nav bar to reduce on scroll.

I feel like the code is basically the same as the first pen aside from moving the nav bar to the very top in this pen.

change "10px" to simply 10 and that should get you moving in the right direction :-)

That did it! Thanks!

Is it just assumed in js that units will be in pixels?

I believe so. You're very welcome. Good luck with the remainder of your project :-)

Also, feel free to mark any of my answers as best. The points make me feel good inside :-D #NotBegging #YesIAm