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 style="padding-top: 60px;">
<div class="mdui-container">
<button id="tooltip" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons"></i></button>
<div class="mdui-m-t-5">
<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>
</div>
<script src="../assets/mdui-v0.2.1/js/mdui.min.js"></script>
</body>
</html>
JavaScript
var inst = new mdui.Tooltip('#tooltip', {
content: 'Print'
});
// 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 target = document.getElementById('tooltip');
target.addEventListener('open.mdui.tooltip', function () {
console.log('open');
});
target.addEventListener('opened.mdui.tooltip', function () {
console.log('opened');
});
target.addEventListener('close.mdui.tooltip', function () {
console.log('close');
});
target.addEventListener('closed.mdui.tooltip', function () {
console.log('closed');
});