Callback event when jQuery 'mmenu' closed

4.9k views Asked by At

Using the jQuery mmenu plugin, I need to call a JavaScript function either after the menu has finished closing or simultaneously. In the documentation I can't see any suggestion for closing entire menu but only for closePanel. I need to insert in mmenu closing function another one (custom) to hide lightbox effect on the page.

<script type="text/javascript">
 $(document).ready(function() {
  $("#menu").mmenu({
    "extensions": [
    "theme-white"
    ],
    "offCanvas": {
        "zposition": "front"
    },
    "slidingSubmenus": false
});
$("#menu").show();
});   
</script>

<script type="text/javascript">
function lightbox(){    
(function($) {      
  // some stuff
})(jQuery);}
</script>

is there a way to bind another function after the plugin has been closed or better, when entire menu closing action?

2

There are 2 answers

0
atmd On

you could try binding to the closing event

$('#mmenu').on('closing.mm', function() {
    // do something
});

There is also a closed event too, so you can use which ever is appropriate

$('#mmenu').on('closed.mm', function() {
    // do something
});
4
circlecube On

I had the same exact question today and after some tinkering, this works for me. Bind to the opened/closed events like so:

$('#mmenu_id').data('mmenu').bind('opened', function () {
    console.log('opened');
});
$('#mmenu_id').data('mmenu').bind('closed', function () {
    console.log('closed');
});