Reputation: 3667
I am trying to build an extremely simple responsive navigation menu. Am having some problems here.
I have created a CodePen here: http://codepen.io/anon/pen/fHsti
Thank you so much for your help!
Upvotes: 2
Views: 1151
Reputation: 3681
Honestly the best way to approach this is to only use JS for managing the state of the nav between media queries, everything else should be tucked away in media queries. Something like MediaCheck or matchMedia is a great way to tie media queries and JS together.
I created a simple demo using your markup, and I think I got the functionality you were looking for. I used mediaCheck to clear away any JS-imposed inline styles between the main breakpoint of 768px.
Upvotes: 3
Reputation: 3985
Change this code. You need the if
statement inside the event handler, otherwise it only binds the event if the width of the window is less than 768px on load.
jQuery("nav p.active").on("click", function(){
if (jQuery(window).width() <= 768) {
jQuery("nav ul").toggle("fast");
}
});
http://codepen.io/anon/pen/BHbon
Upvotes: 3