运行以下任意一个命令来安装driver.js:
# Using npm
npm install driver.js
# Using pnpm
pnpm install driver.js
# Using yarn
yarn add driver.js
或者,您可以使用CDN并在HTML文件中包含脚本:
<script src="https://cdn.jsdelivr.net/npm/driver.js@1.0.1/dist/driver.js.iife.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/driver.js@1.0.1/dist/driver.css"/>
安装完成后,您可以在项目中导入该包。以下示例展示了如何高亮一个元素:
import { driver } from "driver.js";
import "driver.js/dist/driver.css";
const driverObj = driver();
driverObj.highlight({
element: "#some-element",
popover: {
title: "Title",
description: "Description"
}
});
如果您正在使用CDN,您将需要从`window`对象中使用该包:
const driver = window.driver.js.driver;
const driverObj = driver();
driverObj.highlight({
element: "#some-element",
popover: {
title: "Title",
description: "Description"
}
});
继续阅读“基本用法”以了解更多关于该包的信息。