Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback event when jQuery 'mmenu' closed

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?

like image 403
RobertD Avatar asked Jun 23 '15 07:06

RobertD


2 Answers

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');
});
like image 65
circlecube Avatar answered Sep 21 '22 23:09

circlecube


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
});
like image 25
atmd Avatar answered Sep 24 '22 23:09

atmd