Detect if jQuery MMenu is open/active?

安稳与你 提交于 2019-12-11 14:33:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!