HTML
CSS
JavaScript
play_arrow
HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Headroom - 通过 JavaScript 调用</title>
  <link rel="stylesheet" href="../assets/mdui-v0.3.0/css/mdui.min.css"/>
  <style>
    body {
      padding-top: 120px;
    }

    #banner {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 60px;
      background: #607D8B;
    }

    #tool {
      position: fixed;
      top: 80px;
      left: 20px;
    }
  </style>
</head>
<body>

<div id="banner"></div>

<div id="tool">
  <button id="pin" class="mdui-btn mdui-color-pink-accent mdui-m-r-1">pin</button>
  <button id="unpin" class="mdui-btn mdui-color-pink-accent mdui-m-r-1">unpin</button>
  <button id="enable" class="mdui-btn mdui-color-pink-accent mdui-m-r-1">enable</button>
  <button id="disable" class="mdui-btn mdui-color-pink-accent">disable</button>
</div>

<div class="mdui-container">
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
  <p>test</p>
</div>

<script src="../assets/mdui-v0.3.0/js/mdui.min.js"></script>
</body>
</html>
CSS

    
JavaScript
var inst = new mdui.Headroom('#banner');

// method

document.getElementById('pin').addEventListener('click', function () {
  inst.pin();
});

document.getElementById('unpin').addEventListener('click', function () {
  inst.unpin();
});

document.getElementById('enable').addEventListener('click', function () {
  inst.enable();
});

document.getElementById('disable').addEventListener('click', function () {
  inst.disable();
});

// event
var banner = document.getElementById('banner');

banner.addEventListener('pin.mdui.headroom', function () {
  console.log('pin');
});

banner.addEventListener('pinned.mdui.headroom', function () {
  console.log('pinned');
});

banner.addEventListener('unpin.mdui.headroom', function () {
  console.log('unpin');
});

banner.addEventListener('unpinned.mdui.headroom', function () {
  console.log('unpinned');
});