HTML
CSS
JavaScript
HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>抽屉栏导航 - 通过 JavaScript 调用</title>
  <link rel="stylesheet" href="https://cdn.w3cbus.com/library/mdui/1.0.2/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">move_to_inbox</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">star</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">send</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">drafts</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">email</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">delete</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">error</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="https://cdn.w3cbus.com/library/mdui/1.0.2/js/mdui.min.js"></script>
</body>
</html>
CSS

  
JavaScript
var $ = mdui.$;
var inst = new mdui.Drawer('#drawer');

// method
$('#open').on('click', function () {
  inst.open();
});

$('#close').on('click', function () {
  inst.close();
});

$('#toggle').on('click', function () {
  inst.toggle();
});

$('#getState').on('click', function () {
  mdui.alert(inst.getState());
});

// event
$('#drawer').on('open.mdui.drawer', function () {
  console.log('open');
});

$('#drawer').on('opened.mdui.drawer', function () {
  console.log('opened');
});

$('#drawer').on('close.mdui.drawer', function () {
  console.log('close');
});

$('#drawer').on('closed.mdui.drawer', function () {
  console.log('closed');
});