intro.js 中的自定义 HTML 元素

问题描述 投票:0回答:1

我可以直接在介绍消息中添加复选框或自定义 HTML 元素吗?

文档中没有任何有关在介绍消息中添加自定义 HTML 元素的功能。

const handleIntroMessage = () => {
  console.log("!")
  intro.setOptions({
    steps: [
      {
        element: '#lastname',
        intro: 'Last Name of the defendant here.',
        title: 'Last Name'
      },
      {
        element: '#firstname',
        intro: 'First Name of the defendant here.',
        title: 'First Name'
      }
    ]
  });
  intro.setOption("dontShowAgain", true);
  intro.start();
}
javascript reactjs intro.js
1个回答
0
投票

示例

如何将 HTML 代码插入工具 - Intro.js 文档

// Import the React and ReactDOM modules
const { useState, useEffect } = React;

// App component
function App() {
  useEffect(() => {
    // Create Intro.js on component load
    const intro = introJs();
    
    // Define the steps of the introduction
    intro.setOptions({
      steps: [
        {
          intro: "<h2 style='color: red;'>Welcome to the demo application!</h2>",
        },
        {
          element: "#step1",
          intro: "<p style='font-size: 20px;'>This step is an example of an HTML element</p>",
        },
        {
          element: "#step2",
          intro: "<p style='background-color: yellow;'>And this is another HTML element</p>",
        },
      ],
    });
    
    // Start the introduction
    intro.start();
  }, []);

  return (
    <div>
      <h1>React Intro.js Demo</h1>
      <p id="step1">This is an example HTML element.</p>
      <p id="step2">And this is another example HTML element.</p>
    </div>
  );
}

// Render the application to the DOM
ReactDOM.render(<App />, document.getElementById("root"));
<link
  href="https://cdn.jsdelivr.net/npm/intro.js/introjs.min.css"
  rel="stylesheet"
/>

<div id="root"></div>

<script src="https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/intro.js/intro.min.js"></script>

© www.soinside.com 2019 - 2024. All rights reserved.