简单易上手的引导插件——Intro.js

Intro.js

介绍

Intro.js 是一个开源普通轻量级的 Javascript / CSS 库,用于添加分步介绍或提示。只有 10kB 并且没有外部依赖!

不仅提供了自定义选项,可以控制引导窗口的外观和行为。还可以设置样式、主题和动画效果,以及自定义事件和回调函数,以便在引导的不同阶段执行自定义操作

安装使用

使用npm安装

npm install intro.js --save

引入intro方法和样式

import intro from 'intro.js'
import 'intro.js/minified/introjs.min.css'

安装 Introjs 后,有两种方法可以实现引导样式

方法一:使用html

data-introdata-step属性添加到 HTML 元素中;然后调用 introJs().start()

<div data-title="Welcome!" data-intro="Hello World! 👋" class="card-demo">
  <div class="card shadow--md">
    <div class="card__image" data-intro="Intro.js can highlight on elements">
      <img
        src="..."
        alt="Image alt text"
        title="Logo Title Text 1"
      />
    </div>
    <div class="card__body" data-title="Farewell!" data-intro="And this is the last step!">
      <h4>Quaco Lighthouse</h4>
      <small>
        The Quaco Head Lighthouse is a well maintained lighthouse close to St.
        Martins. It is a short, beautiful walk to the lighthouse along the
        seashore.
      </small>
    </div>
  </div>
</div>
const introJs = intro();
introJs().start();

在这里插入图片描述
HTML中可配置如下属性属性:

  1. data-intro:步骤的提示文本
  2. data-step:(可选)定义步骤的编号(优先级)
  3. data-tooltipClass:(可选)为提示定义CSS类
  4. data-highlightClass:(可选)将CSS类附加到helperLayer
  5. data-position:定义提示的位置,top,left,right,bottom,bottom-left-aligned(同bottom), bottom-middle-aligned,bottom-right-aligned或auto(检测元件的位置,并自动分配正确的位置)。默认是bottom
  6. data-scrollTo:滚动到的元素,element或tooltip。默认值为element。
方法二:使用 JSON 定义

在setOptions里面加入需要引导的dom节点

introJs().setOptions({
  steps: [{
    title: 'Welcome',
    intro: 'Hello World! 👋'
  },
  {
    element: document.querySelector('.card-demo'),
    intro: 'This step focuses on an image'
  },
  {
    title: 'Farewell!',
    element: document.querySelector('.card__image'),
    intro: 'And this is our final step!'
  }]
}).start();

在这里插入图片描述
Intro.js 会自动查找工具提示的最佳位置,但也可以使用配置 position 显式定义每个步骤的工具提示位置

introJs().setOptions({
  steps: [
  {
    element: document.querySelector('.card-demo'),
    intro: 'Tooltip has position right',
    position: 'right'
  },
  ]
}).start();

在这里插入图片描述

虽然说大小只有10kb,但是intro.js依然可以轻松创建引导教程,它提供了简单的 API,可以根据需要定义步骤、提示文本和高亮显示的元素。

github:https://github.com/usablica/intro.js
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个使用 Intro.js 生成引导页面的示例代码。这个示例中,我们将介绍如何创建一个简单引导页面,并使用一些样式来美化它: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Intro.js 示例</title> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/intro.js/3.3.1/introjs.min.css"> <style> .introjs-tooltip { max-width: 400px; border-radius: 3px; box-shadow: 0 0 20px rgba(0,0,0,0.3); background-color: #fff; color: #333; } .introjs-arrow { border-top-color: #fff; } .introjs-tooltipbuttons { text-align: center; } .introjs-button { background-color: #e1e1e1; color: #333; border-radius: 3px; padding: 5px 10px; margin: 5px; cursor: pointer; } .introjs-button:hover { background-color: #d2d2d2; } .introjs-button:focus { outline: none; } </style> </head> <body> <h1>Intro.js 示例</h1> <p>这是一个使用 Intro.js 创建的引导页面示例。</p> <button id="startBtn">开始引导</button> <script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/3.3.1/intro.min.js"></script> <script> document.getElementById("startBtn").addEventListener("click", function() { introJs().setOptions({ steps: [ { element: document.querySelector('h1'), intro: "这是页面的标题。" }, { element: document.querySelector('p'), intro: "这是页面的主体内容。" }, { element: document.querySelector('#startBtn'), intro: "这是开始引导按钮。", position: 'bottom' } ], showBullets: false, exitOnOverlayClick: false, exitOnEsc: false }).start(); }); </script> </body> </html> ``` 在这个示例中,我们使用了一些 CSS 样式来美化 Intro.js 的工具提示框和按钮。我们还使用了 `setOptions()` 方法来设置引导页面的参数选项,例如 `steps`、`showBullets`、`exitOnOverlayClick` 和 `exitOnEsc` 等。最后,我们在按钮的点击事件中调用 `introJs().start()` 方法启动引导页面。 你可以根据自己的需求调整这个示例代码,以生成自己的引导页面。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值