jQuery Toggle animation is not working

2

I have this code, and I would like to toggle the click but it is not working. Any tips sff?

HTML:

<body>
<img id="topBar" src="imgs/topBar.png">
<div id ="wrapper">
    <nav>
        <a href="index.php"><img id="logo" src="imgs/logo.jpg"></a>
        <a href="index.php"><img id="logoMob" src="imgs/logo.jpg"></a>
        <div id ="btMob"><h1>MENU</h1></div>
        <ul>
            <li><a href="Linguas.php">Línguas</a></li>
            <li><a href="Cursos.php">Cursos</a></li>
            <li><a href="Learning_Portuguese.php">Learning Portuguese</a></li>
            <li><a href="Testemunhos.php">Testemunhos</a></li>
            <li><a href="Sobre_nos.php">Sobre nós</a></li>
            <li><a href="FAQ.php">FAQ</a></li>
            <li id ="cont"><a>contactos</a><img src="imgs/arrow.png"></li>
        </ul>
    </nav>

CSS:

#logo {
    height: 100%;
    float: left;
    width: auto;
    border-left: 1500px solid #fff;
    margin-left: -1500px;
}
#logoMob {
    height: 100%;
    float: left;
    width: auto;
    margin: 0;
    display: none;
}
#btMob {
    width: 200px;
    cursor: pointer;
    height: 100%;
    margin: 0 0 0 63px;
    background-color: #fff;
    text-align: center;
    display: none;
    position: absolute;
}


@media only screen and (max-width: 900px) {
#logo {
        display: none;
    }
#logoMob {
        display: inline;
    }
    #btMob {
        display: block;
    }
}

jQuery:

       $('#logoMob, #btMob').click(function() {
          $('nav ul').stop(true).animate({
            left:"328px"
          }, 300, 'linear');
        }, function() {
          $('nav ul').stop(true).animate({
            left:"0"
          }, 300, 'linear');
        });
    
asked by anonymous 19.05.2014 / 11:28

2 answers

2

The .click() of jQuery does not support more than one function as a parameter. The .hover() is that you have this option for the hover-out.

What you can do is create a flag / flad: link

var bandeira = false;
$('#logoMob, #btMob').click(function () {
    $('nav ul').stop(true).animate({
        left: (bandeira = (!bandeira)) ? "328px" : "0px"
    }, 300, 'linear');
});
    
19.05.2014 / 11:42
0

It does not work because clicking is performing the second function:

 $('#logoMob, #btMob').click(function() {

     //NÃO EXECUTA ESSE TRECHO AO FAZER CLICK
      $('nav ul').stop(true).animate({
        left:"328px"
      }, 300, 'linear');
    }, function() {

      //EXECUTA ESSE TRECHO AO FAZER CLICK
      $('nav ul').stop(true).animate({
        left:"0"
      }, 300, 'linear');
    });
    
19.05.2014 / 11:41