【driver.js】基础使用

这篇具有很好参考价值的文章主要介绍了【driver.js】基础使用。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

介绍

driver.js:
轻量级、无依赖性、普通的 JavaScript 引擎,可在整个页面上推动用户的注意力;

  • 🔆突出显示页面上的任何(字面上的任何)项目
  • ✋阻止用户交互
  • 📣 创建功能介绍
  • 👓为用户添加焦点转移器
  • 🛠️ 高度可定制——在任何地方使用它进行叠加
  • ⌨️ 用户友好 –按键控制
  • 🆓 MIT 许可– 免费供个人和商业使用
  • 🕊️ 轻量级——压缩后只有~4kb
  • 🌀跨所有主要浏览器的一致行为

1.安装

Node方式:

yarn add driver.js
# 或者 
npm install driver.js

CDN方式:

<script src="https://unpkg.com/driver.js/dist/driver.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/driver.js/dist/driver.min.css">

2.相关配置参数及接口

2.1.初始化参数

&:可通过在步骤定义中提供特定步骤来覆盖初始化配置(所有按钮选项)

const driver = new Driver({
  // className来包装驱动程序。js弹出窗口
  // className to wrap driver.js popover
  className: 'scoped-class', 
  // 更改亮显元素时设置动画
  // Animate while changing highlighted element
  animate: true,  
  // 背景不透明度(0表示仅弹出窗口,没有覆盖)
  // Background opacity (0 means only popovers and without overlay)
  opacity: 0.75,  
  // 元件与边缘周围的距离
  // Distance of element from around the edges
  padding: 10,    
  // 单击覆盖是否应关闭
  // Whether clicking on overlay should close or not
  allowClose: true, 
  // 如果移动到覆盖上的下一步,请单击
  // Should it move to next step on overlay click
  overlayClickNext: false, 
  // 最后一个按钮上的文本
  // Text on the final button
  doneBtnText: 'Done', 
  // 此步骤关闭按钮上的文本
  // Text on the close button for this step
  closeBtnText: 'Close', 
  // 此步骤的下一个按钮文本
  // Next button text for this step
  nextBtnText: 'Next', 
  // 此步骤的上一个按钮文本
  // Previous button text for this step
  prevBtnText: 'Previous', 
  // 不在页脚中显示控制按钮
  // Do not show control buttons in footer
  showButtons: false, 
  // 允许通过键盘进行控制(退出以关闭,箭头键移动)
  // Allow controlling through keyboard (escape to close, arrow keys to move)
  keyboardControl: true, 
  // 如果可能,我们使用“scrollIntoView()”,如果需要,请将其选项传递给此处
  // We use `scrollIntoView()` when possible, pass here the options for it if you want any
  scrollIntoViewOptions: {}, 
  // 当元素将被突出显示时调用
  // Called when element is about to be highlighted
  onHighlightStarted: (Element) {}, 
  // 当元素完全突出显示时调用
  // Called when element is fully highlighted
  onHighlighted: (Element) {},
  // 取消选择元素时调用
  // Called when element has been deselected
  onDeselected: (Element) {}, 
  // 在即将清除覆盖时调用
  // Called when overlay is about to be cleared
  onReset: (Element) {},    
  // 在任何步骤上移动到下一步骤时调用    
  // Called when moving to next step on any step
  onNext: (Element) => {},      
  // 在任何步骤上移动到下一步骤时调用
  // Called when moving to next step on any step
  onPrevious: (Element) => {},  
});

2.2.步骤参数

// 以下是可在每个步骤中传递的一组选项
const stepDefinition = {
  // 要突出显示的查询选择器字符串或节点
  // Query selector string or Node to be highlighted
  element: '#some-item',        
  // 如果为空或未给出,则不会弹出窗口
  // There will be no popover if empty or not given
  popover: {                    
   // className to wrap this specific step popover in addition to the general className in Driver options
    className: 'popover-class', 
    // 弹出窗口上的标题
    // Title on the popover
    title: 'Title',    
    // 主要描述内容         
    // Body of the popover
    description: 'Description', 
    // 不在页脚中显示控制按钮
    // Do not show control buttons in footer
    showButtons: false,   
    // 此步骤关闭按钮上的文本      
    // Text on the close button for this step
    closeBtnText: 'Close',      
    // 此步骤的下一个按钮文本
    // Next button text for this step
    nextBtnText: 'Next',    
    // 此步骤的上一个按钮文本    
    // Previous button text for this step
    prevBtnText: 'Previous',    
  }
};

2.3.可支持的方法

const driver = new Driver(driverOptions);

// 检查驱动程序是否激活
// Checks if the driver is active or not
const isActivated = driver.isActivated; 
// 移至步骤列表中的下一步
// Moves to next step in the steps list
driver.moveNext();     
// 移至步骤列表中的上一步
// Moves to previous step in the steps list
driver.movePrevious(); 
// 开始执行定义的步骤
// Starts driving through the defined steps
driver.start(stepNumber = 0);  
// 使用查询选择器或步骤定义突出显示元素
// highlights the element using query selector or the step definition
driver.highlight(string|stepDefinition); 
// 重置覆盖并清除屏幕
// Resets the overlay and clears the screen
driver.reset(); 
// 检查是否有任何突出显示的元素
// Checks if there is any highlighted element
driver.hasHighlightedElement(); 
// 检查是否有下一步要移动
// Checks if there is next step to move to
driver.hasNextStep(); 
// 检查是否有上一步要移动到
// Checks if there is previous step to move to
driver.hasPreviousStep(); 

// 防止当前移动。如果需要,可在“onNext”或“onPrevious”中使用
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
// 执行一些异步任务并手动转到下一步
// perform some asynchronous task and manually move to next step
driver.preventMove();

// 获取屏幕上当前突出显示的元素
// Gets the currently highlighted element on screen
const activeElement = driver.getHighlightedElement();
const lastActiveElement = driver.getLastHighlightedElement();
// 获取活动元素的屏幕坐标
// Gets screen co-ordinates of the active element
activeElement.getCalculatedPosition(); 
// 隐藏弹出窗口
// Hide the popover
activeElement.hidePopover();  
// 显示弹出窗口
// Show the popover
activeElement.showPopover();  
// 获取此元素后面的DOM元素
// Gets the DOM Element behind this element
activeElement.getNode();  

3.示例

// 导入库和CSS文件
import Driver from 'driver.js';
import 'driver.js/dist/driver.min.css';

3.1.突出显示单个元素 - 没有弹出窗口

const driver = new Driver();
driver.highlight('#create-post');

【driver.js】基础使用

3.2.高亮单个元素 - 并弹出提示框

const driver = new Driver();
driver.highlight({
  element: '#some-element',
  popover: {
    title: 'Did you know?',
    description: 'You can add HTML in title or description also!',
  }
});

【driver.js】基础使用文章来源地址https://www.toymoban.com/news/detail-413209.html

到了这里,关于【driver.js】基础使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 车载以太网基础篇之Eth Driver

    车载以太网基础篇之Eth Driver

    车载以太网基础篇之Ethernet Driver 前言 首先,请问大家几个小小问题,你清楚: 你知道Eth Driver模块的主要作用是什么吗? EthDriver与以太网控制器,以太网收发器,都有哪些关系呢? Eth Driver的常见函数接口有哪些呢? Eth Driver一般存在区别其他驱动特有的特性呢? 今天,我们

    2024年02月03日
    浏览(8)
  • selenium driver相关使用

     1) 打开浏览器,创建driver对象 from selenium import webdriver import time from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.maximize_window() driver.implicitly_wait(5) url = \\\"https://www.baidu.com/\\\" driver.get(url)         # 浏览器加载url 2) driver 属性   driver.get() 在浏览器打开url driver.clos

    2024年02月11日
    浏览(6)
  • chrome Driver 使用教程

    Chrome Driver 是一款实用的chrome浏览器驱动工具,能够用于自动化测试、网络爬虫和操作浏览器,其主要作用是模拟浏览器操作。 ## 下载地址 [Chrome for Testing availability](Chrome for Testing availability)

    2024年02月08日
    浏览(7)
  • mongodb-cxx-driver使用

    mongodb-cxx-driver使用

    mongocxx driver 是构建在 MongoDB C driver 之上的 mongo官方推荐 针对mongocxx-3.7.x,需要libmongoc 1.22.1或更高版本。 对于mongocxx-3.6.x,需要libmongoc 1.17.0或更高版本。 对于mongocxx-3.5.x,需要libmongoc 1.15.0或者更高版本。 对于mongocxx-3.4.x,需要libmongoc 1.13.0或者更高版本。 对于mongocxx-3.3.x,需

    2024年02月05日
    浏览(5)
  • 使用qsqlmysql操作mysql提示Driver not loaded

    使用qsqlmysql操作mysql提示Driver not loaded

    环境: win10 IDE: qt creator 编译器: mingw32 这里简单的记录下。我遇到的情况是在IDE使用debug和release程序都是运行正常,但是当我编译成发布版本之后。老是提示Driver not load。 这就很奇诡了。 回顾了下编译的时候是需要在使用qt先编译下libqsqlmysql.dll的。 我是使用了MySQL Server 5.5版

    2024年02月12日
    浏览(10)
  • Driver8833电机驱动模块的使用(STM32为主控)

    Driver8833电机驱动模块的使用(STM32为主控)

    一、硬件 STM32C8T6、STLINK下载器 Driver8833:TI公司的DRV8833是双桥马达驱动器解决方案,包括有两个H桥驱动器,可驱动两个DC电刷马达,或一个步进马达, 螺线管和其它电感负载. DRV8833具有PWM绕组电流调整/限制,H桥的输出电流1.5A RMS,2A峰值,工作电压2.7V-10.8V。 编码电机 二、Driver8833的使

    2024年02月01日
    浏览(11)
  • vue+neo4j +纯前端(neovis.js / neo4j-driver) 实现 知识图谱的集成 大干货--踩坑无数!!!将经验分享给有需要的小伙伴

    简单来说,这是一种比较热门的图数据库,图数据库以图形形式存储数据。 它以节点,关系和属性的形式存储应用程序的数据。 一个图由无数的节点和关系组成。 安装图数据库在这里就不介绍了,本篇主要介绍如何连接neo4j数据库,将知识图谱成功显示在前端页面中。 1.、

    2024年02月02日
    浏览(214)
  • Java selenium使用出现The path to the driver executable must be set by the webdriver.edge.driver system

    Java selenium使用出现The path to the driver executable must be set by the webdriver.edge.driver system

    2023年3月份Java selenium开始使用出现The path to the driver executable must be set by the webdriver.edge.driver system property; for more; 尝试更换chrome driver,以及根据网上的使用白名单来解决都不生效, 后续发现需要更新Java selenium的使用方式: 以Windows为例需要在之前配置上加上: 1、为driver设置

    2024年01月22日
    浏览(7)
  • 【VideoJs】初识videojs && video.js 视频播放器的基本使用 && videojs基础用法 && videojs视频播放器 && vue3中使用videojs

    免费,开源 插件多 可自定义 【推】 虽然,但是Videojs算好了,但我觉得有点杂,特别是文档与插件,且自定义插件有点困难,也可能是我比较菜吧 相比之下,我还是强烈推荐 【Xgplayer ——点我进入】 备用地址 http://t.csdn.cn/H0cAV Xgplayer 优点 优雅、美观 文档清晰明了 大厂出

    2024年02月03日
    浏览(26)
  • 嵌入式Linux 开发经验:platform_driver_register 的使用方法

    嵌入式Linux 开发经验:platform_driver_register 的使用方法

    嵌入式Linux 设备驱动开发时,经常遇到平台驱动 platform_driver_register 的注册,最近深入了看了驱动开发为何使用平台驱动 开发一个设备驱动时,为了实现 设备的 打开、关闭、控制等操作,可以注册为 Linux misc 设备,不过在这之前,可以先使用 platform_driver_register 注册平台驱动

    2024年01月15日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包