1.引入JS,CSS库文件
<link rel="stylesheet" href="assets/js/driver.min.css">
<script src="assets/js/driver.min.js"></script>
2.HTML元素(部分)
<section class="row text-center" id="driver-demo-head">
<div class="col-md-12">
<h1>
<img id="logo_img" src="assets/image/driver.png" style="height:67px;"/>
<span id="name_driver">Driver.js</span>
</h1>
</div>
//省略部分HTML代码
</section>
3.初始化引导插件,绑定事件等
document.addEventListener("DOMContentLoaded", function () {
//定义引导步骤
const tourSteps = [
{
element: document.getElementById('driver-demo-head'),
popover: {
title: 'Before we start',
description: 'This is just one use-case, make sure to check out the rest of the docs below.',
nextBtnText: 'Okay, Start!'
}
},
//此处省略部分代码
];
//初始化带动画的引导插件
const animatedTourDriver = new Driver({
animate: true,
opacity: 0.8,
padding: 5,
showButtons: true,
});
//初始化不带动画的引导插件
const boringTourDriver = new Driver({
animate: false,
opacity: 0.8,
padding: 5,
showButtons: true,
});
//将步骤应用到引导插件上
boringTourDriver.defineSteps(tourSteps);
animatedTourDriver.defineSteps(tourSteps);
//默认显示带动画的引导示例
animatedTourDriver.start();
//绑定事件
document.querySelector('#animated-tour')
.addEventListener('click', () => {
if (boringTourDriver.isActivated) {
boringTourDriver.reset(true);
}
animatedTourDriver.start();
});
document.querySelector('#boring-tour')
.addEventListener('click', () => {
if (animatedTourDriver.isActivated) {
animatedTourDriver.reset(true);
}
boringTourDriver.start();
});
});
更多使用方法请参考官方文档:https://kamranahmed.info/driver.js/
the end