vue使用driver.js完成页面引导的功能

需求:用户首次进入的时候肯定不知道一些功能是干什么在哪里,之后给用户一个页面引导,教他怎么做。

点击插件driver.js官方文档

效果:

 1.下载driverjs

我默认下载的是最新版 "driver.js": "^1.0.5",,其他的低版本可能导入和使用方式不一样哈,别下错了

npm install driver

2.导入

这个包比较小,只有18k

import { driver } from 'driver.js';
import 'driver.js/dist/driver.css';

3.写几个需要向导的div内容,并且设置id值,用于锁定

 <div id="some-element" class="top">
                <h2>第一步</h2>
                <section>巴拉巴拉</section>
            </div>
                 <!-- 左 -->
                 <div id="step-item-3" class="left">
                <h2>第二步</h2>
                <section>巴拉巴拉</section>
            </div>
            <div id="step-item-4" class="bottom">
                <h2>第三部</h2>
                <section>结束</section>
            </div>

4.引导的内容和定位

每一个元素代表的是每一步

element:用户绑定需要向导的div中id的值,也可以用.类名,或者div,为了准确性最好还是用id值绑定,优先级高点

steps: [
                {
                    element: '#some-element',
                    popover: {
                        title: 'Animated Tour Example',
                        description: "Here is the code example showing animated tour. Let's walk you through it.",
                        side: 'right',//弹窗在元素的位置
                        align: 'start'
                    }
                },
                {
                    element: '#step-item-3',
                    popover: {
                        title: 'Import the Library',
                        description: 'It works the same in vanilla JavaScript as well as frameworks.',
                        side: 'left',
                        align: 'start'
                    }
                },
                {
                    element: '#step-item-4',
                    popover: {
                        title: 'Importing CSS',
                        description: 'Import the CSS which gives you the default styling for popover and overlay.',
                        side: 'bottom',
                        align: 'start'
                    }
                },
                {
                    popover: {
                        title: 'Happy Coding',
                        description: 'And that is all, go ahead and start adding tours to your applications.'
                    }
                }
            ]

5.点击按钮后开始绑定

   const driverObj = driver({
                showProgress: true,
                steps: this.steps
            });
            driverObj.drive();
        }

6.完整代码

<template>
    <div class="content-box">
        <div class="container">
            <el-button @click="query">向导指引</el-button>
            <el-button @click="driverobj">步骤条向导</el-button>
            <div id="some-element" class="top">
                <h2>第一步</h2>
                <section>巴拉巴拉</section>
            </div>
                 <!-- 左 -->
                 <div id="step-item-3" class="left">
                <h2>第二步</h2>
                <section>巴拉巴拉</section>
            </div>
            <div id="step-item-4" class="bottom">
                <h2>第三部</h2>
                <section>结束</section>
            </div>
       
        </div>
    </div>
</template>

<script>
import { driver } from 'driver.js';
import 'driver.js/dist/driver.css';
export default {
    data() {
        return {
            steps: [
                {
                    element: '#some-element',
                    popover: {
                        title: 'Animated Tour Example',
                        description: "Here is the code example showing animated tour. Let's walk you through it.",
                        side: 'right',//弹窗在元素的位置
                        align: 'start'
                    }
                },
                {
                    element: '#step-item-3',
                    popover: {
                        title: 'Import the Library',
                        description: 'It works the same in vanilla JavaScript as well as frameworks.',
                        side: 'left',
                        align: 'start'
                    }
                },
                {
                    element: '#step-item-4',
                    popover: {
                        title: 'Importing CSS',
                        description: 'Import the CSS which gives you the default styling for popover and overlay.',
                        side: 'bottom',
                        align: 'start'
                    }
                },
                {
                    popover: {
                        title: 'Happy Coding',
                        description: 'And that is all, go ahead and start adding tours to your applications.'
                    }
                }
            ]
        };
    },
    mounted() {},
    methods: {
        query() {
            const driverObj = driver();
            driverObj.highlight({
                element: '#some-element',
                popover: {
                    title: 'Title',
                    description: 'Description'
                }
            });
        },
        driverobj() {
            const driverObj = driver({
                showProgress: true,
                steps: this.steps
            });
            driverObj.drive();
        }
    }
};
</script>

<style lang="scss" scoped>
.bottom{
    width: 300px;
    margin-top: 400px;

}
.left{
    width: 300px;
    margin-left: 400px;
}
.top{
    width: 300px;
}
</style>

文章到此结束,希望对你有所帮助~ 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值