vendredi 9 octobre 2015

JQuery Click function is only running the last IF statement

I have written a basic jQuery function which is designed to open and close the bottom menu (JSFiddle). However it seems to only be firing the last if statement in the click function.

I have created a variable called openNclose which is defaulted to false as the menu isn't open. Once opened, it should change to true and fire off the closing if statement, however this isn't working.

 $(menuContainer).click(function() {

        if (openNclose == true) {    
            $(menuContainer).css("height", "50px");
            $(menuOpen).css("bottom", "50px");
            openNclose = false;
        }

        if (openNclose == false) {
            $(menuContainer).css("height", "200px"); 
            $(menuOpen).css("bottom", "200px");
            openNclose = true;
        }

        console.log(openNclose);
    }); 

Aucun commentaire:

Enregistrer un commentaire