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.2.1/css/mdui.min.css"/>
</head>
<body class="mdui-drawer-body-left" style="padding-top: 20px;">
<div class="mdui-drawer" id="drawer">
<ul class="mdui-list">
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Inbox</div>
</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Starred</div>
</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Sent mail</div>
</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Drafts</div>
</li>
<li class="mdui-subheader">Subheader</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">All mail</div>
</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Trash</div>
</li>
<li class="mdui-list-item mdui-ripple">
<i class="mdui-list-item-icon mdui-icon material-icons"></i>
<div class="mdui-list-item-content">Spam</div>
</li>
</ul>
</div>
<div class="mdui-container">
<button id="open" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">open</button>
<button id="close" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">close</button>
<button id="toggle" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">toggle</button>
<button id="getState" class="mdui-btn mdui-color-pink-accent mdui-m-a-1">getState</button>
</div>
<script src="../assets/mdui-v0.2.1/js/mdui.min.js"></script>
</body>
</html>
JavaScript
var inst = new mdui.Drawer('#drawer');
// method
document.getElementById('open').addEventListener('click', function () {
inst.open();
});
document.getElementById('close').addEventListener('click', function () {
inst.close();
});
document.getElementById('toggle').addEventListener('click', function () {
inst.toggle();
});
document.getElementById('getState').addEventListener('click', function () {
mdui.alert(inst.getState());
});
// event
var drawer = document.getElementById('drawer');
drawer.addEventListener('open.mdui.drawer', function () {
console.log('open');
});
drawer.addEventListener('opened.mdui.drawer', function () {
console.log('opened');
});
drawer.addEventListener('close.mdui.drawer', function () {
console.log('close');
});
drawer.addEventListener('closed.mdui.drawer', function () {
console.log('closed');
});