HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>菜单 - 通过 JavaScript 调用</title>
<link rel="stylesheet" href="../assets/mdui-v0.4.2/css/mdui.min.css"/>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-pink">
<div class="mdui-container mdui-p-t-5">
<ul class="mdui-menu" id="menu">
<li class="mdui-menu-item">
<a href="javascript:;" class="mdui-ripple">Refresh</a>
</li>
<li class="mdui-menu-item">
<a href="javascript:;" class="mdui-ripple">Settings</a>
</li>
<li class="mdui-menu-item">
<a href="javascript:;" class="mdui-ripple">Send feedback</a>
</li>
<li class="mdui-menu-item">
<a href="javascript:;" class="mdui-ripple">Help</a>
</li>
<li class="mdui-menu-item">
<a href="javascript:;" class="mdui-ripple">Signout</a>
</li>
</ul>
<button id="open" class="mdui-btn mdui-color-pink-accent">open</button>
</div>
<script src="../assets/mdui-v0.4.2/js/mdui.min.js"></script>
</body>
</html>
JavaScript
var inst = new mdui.Menu('#open', '#menu');
// method
document.getElementById('open').addEventListener('click', function () {
inst.open();
});
// event
var dialog = document.getElementById('menu');
dialog.addEventListener('open.mdui.menu', function () {
console.log('open');
});
dialog.addEventListener('opened.mdui.menu', function () {
console.log('opened');
});
dialog.addEventListener('close.mdui.menu', function () {
console.log('close');
});
dialog.addEventListener('closed.mdui.menu', function () {
console.log('closed');
});