J. Doe J. Doe - 1 year ago 49
jQuery Question

jQuery hamburger menu - multiple events called

$( document ).on( "vclick", '#icon', function() {

$("#navigation").animate({height: 'toggle'}, 600, "linear");

});


Hello,

I currently have a hamburger menu that works perfectly except for one thing. If I click the
#icon
10 times, it will execute the code 10 times, I wonder if its possible to make it only clickable when its finished and remove the whole queue system.

Thanks in advance.

Answer Source

You could probably do something in the lines of this:

JavaScript

var animating = false;
$(document).on( "vclick", '#icon', function() {
   if(!animating) {
      animating = true;
      $("#navigation").animate({height: 'toggle'}, 600, "linear", function() {
         animating = false;
      });
   }
});