Reputation: 207
I'm trying to figure out a way to trigger a submenu from outside the mmenu structure.
Opening a submenu with a link directly refering to the mmenu id, doesn't work:
<div class="content">
<a href="#mm-2">Open submenu from here</a>
</div>
Upvotes: 2
Views: 1122
Reputation: 429
Check This fiddle for open a menu dynamically.I've user trigger event of the menu.
You can add id of the menu as data-href
in a tag like the following
<a href="javascript:void(0);" data-href="#mm-2" class="open-dynamic"><span>Open the submenu "80% werken" from here</span></a>
You can generate all menu external link by adding different id in the a tag.
And the following script will work for open a menu.
$(document).on("click", ".open-dynamic", function () {
$(document).find("[href='" + $(this).attr("data-href") + "']").trigger("click");
});
Upvotes: 1
Reputation: 2262
Add the id external
or whatever you like to your external anchor. Also add an id to the ul
constituing your "80% werken" menu. (In this example I used 80_sub
). Now add the following to your js script:
$('#external').click(function(ev) {
ev.preventDefault(); //Avoid mmenu to get the click and close
var api = $("#my-menu").data( "mmenu" );
api.openPanel( $("#80_sub") );
});
We are manually manipulating the menu using the API.
Edit: Working example based on your fiddle.
Upvotes: 1