0

I am almost finished building a responsive navigation for my website, but I can't seem to get the Navigation to hide under a "Menu" button until clicked. Right now, when the window is small enough to meet the css queries, I just get a navigation that is stacked and all visible. Here is my javascript that I'm using. I hope someone can help me out here.

<script>
$(document).ready(function() {
$(".toggleMenu").css("display", "none");
$(".nav li").hover(function() {
    $(this).addClass('hover');
}, function() {
    $(this).removeClass('hover');
});
});
</script>
<script>
$(document).ready(function() {
$(".nav li a").each(function() {
    if ($(this).next().length > 0) {
        $(this).addClass("parent");
    };
})
if (ww < 800) {
    $(".toggleMenu").css("display", "inline-block");
    $(".toggleMenu").click(function(e) {
e.preventDefault();
$(".nav").toggle();
});

if (ww < 800) {
$(".toggleMenu").css("display", "inline-block");
$(".nav").hide();
} else {
    $(".toggleMenu").css("display", "none");
    $(".nav li").hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
}
</script>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Can you explain where you are setting `ww`, which I imagine is window width in your code, as I do not see it here. Also is there a reason you want to use javascript over CSS' @media condition? – KHeaney Feb 10 '15 at 18:32
  • This is my media query and window width that i'm using @media screen and (max-width: 800px) { .nav > li { float: none; } .nav ul { display: block; width: 100%; } .nav > li.hover > ul , .nav li li.hover ul { position: static; } } .nav > li > .parent { background-position: 95% 50%; } .nav li li .parent { background-image: url("http://vignette4.wikia.nocookie.net/civilization/images/c/cc/Left_arrow_(CivBE).png"); background-repeat: no-repeat; background-position: 95% 50%; } – Airsoft R Us Tactical Feb 10 '15 at 23:52
  • Have you already looked at this question? http://stackoverflow.com/a/4092390/3915817 – KHeaney Feb 11 '15 at 14:25

0 Answers0