6

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?

circlecube
  • 706
  • 1
  • 10
  • 19
RobertD
  • 61
  • 1
  • 3

2 Answers2

6

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');
});
circlecube
  • 706
  • 1
  • 10
  • 19
  • This event is after the panel has closed... If you want the event to occur as soon as you request the closing, what do you do then? – Jimmyt1988 Aug 13 '15 at 13:07
  • 1
    This may help, http://mmenu.frebsite.nl/documentation/api.html I don't see an event available for binding before the action. You could attach an event listener to the close button itself? – circlecube Aug 14 '15 at 11:33
  • 2
    The "atmd" answer states the event "closing", which works perfectly. Thanks man. – Jimmyt1988 Aug 14 '15 at 12:26
  • take into account that there are also "opening" and "closing" events – Denis Dec 28 '15 at 09:11
4

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
});
atmd
  • 7,430
  • 2
  • 33
  • 64