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

Treehouse Side Drawer Menu Javascript

Hey everyone

Been looking at the Treehouse homepage menu in depth for a while now (specifically the mobile site) and I cannot for the life of me figure out what javascript it uses to add its shelf open state on both the body element and the nav.

So far

I was able to recreate the animated burger to X icon.

I know that the shelf uses translate(x): to move both the nav and the body across. (-270px)

But cannot work out how it fires both the moving of the nav and body elements of these events while clicking the icon. All my attempts to recreate this have failed :(

Can someone find how it does this within the javascript? Or show how to deconstruct javascript? I find javascript very hard to learn just from looking at websites, the code is often very hard to find.

1 Answer

This is as much CSS as it is JavaScript.

All the JS is doing is adding the mobile-nav-expanded class to the html element (and current to the li element with the id of mobile-nav-toggle).

Then CSS is used to position the body (or rather the div with the id of container) to the left off the viewable area of the page, and the mobile menu is effectively sitting fixed to the right hand side underneath, so it gets 'revealed'.

There's even tricky ways to do this all in CSS, without JavaScript.

Do some searches for 'off-screen navigation menu' or 'css drawer menu' for an endless supply of examples!