javascript - Fade div in and out using the same link onclick -


i can fade div in click how use same click toggle div, i.e. fade div in on click , fade div out on second click.

i'd navbar-toggle clicked once open overlay , clicked again fade out overlay.

<script>   $(document).ready(function(e) {    $('.navbar-toggle').click(function(e){         $('.overlay, .popup').fadein('slow');   });    $('.navbar-toggle').click(function(e){              $('.overlay, .popup').fadein('slow');   });  }); </script> 

you can couple of ways:

solution 1:

use toggle()

$('.navbar-toggle').click(function(e){         $('.overlay, .popup').toggle('fast'); }); 

jsfiddle demo

solution 2:

use fadetoggle()

$('.navbar-toggle').click(function(e){         $('.overlay, .popup').fadetoggle(300); }); 

jsfiddle demo

solution 3:

have hidden class , check see if exists


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -