问题
I'm using jQuery MMenu and need to use the API to detect whether or not the menu is open.
I've looked over their Events page, but I cannot figure out how to get it's status.
Will someone please give me an example of how to do this?
回答1:
From the docs stated, you can use:
1) opening
event to trigger your function when the menu is opening.
$("#nav").mmenu().trigger("open.mm").on("opening.mm", function() {
alert( "The menu is opening" );
});
2) opened
event to trigger your function when the menu is finished opening
$("#nav").mmenu().trigger("open.mm").on("opened.mm", function() {
alert( "The menu has just been opened." );
});
Edit: When your menu
is active, it will has class mm-opened
in <nav id="left">
, you can check:
$('button').click(function() {
if($('#left').hasClass('mm-opened')) {
$("#nav").trigger("close.mm")
}
});
来源:https://stackoverflow.com/questions/22003846/detect-if-jquery-mmenu-is-open-active