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 trialDan-Thomas Tveita
107 PointsWordpress _s:theme responsive navigation
Im building my site on the Underscores wordpress theme. But im having some problems with the included responsive navigation.
So basically the navigation ul
is first hidden, then theres a media-query displaying it after 37.5ems. The menu-toggle-button is displayed, but hidden after the mediaquery. This is logical and works fine.
The media query looks like this:
/* Small menu. */
.menu-toggle,
.main-navigation.toggled ul { /* '.toggled' is added through javascript */
display: block;
}
@media screen and (min-width: 37.5em) {
.menu-toggle {
display: none;
}
.main-navigation ul {
display: block;
}
}
Problem is that when resizing back out, before clicking the button (that changes the class) the main-navigation ul
is still hidden. The class only changes on-click, not on resize.
Question is, if i can get some help making the javascript change the class when resizing the window back to above the 37.5ems...?
Was this understandable at all?
here is the javascript http://pastebin.com/jHvvVF5q
1 Answer
Dan-Thomas Tveita
107 PointsHmm, i think i managed to solve it myself like this;
if (matchMedia) {
var mq = window.matchMedia("(min-width: 830px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
function WidthChange(mq) {
container.className = container.className.replace( ' toggled', '' );
}
Ill leave the question open for a little while until ive tested it. But it seems to be working now.
Dan-Thomas Tveita
107 PointsDan-Thomas Tveita
107 PointsSummary
display:block;
state, and so the navigation is completely invisible (obviously)Problem would be solved if the included javascript would change the class back, after resizing the window back to 37.5ems+
Or is there something im missing here? :)