我正在使用intro.js的react包装器。我正在尝试将其集成到功能组件中。这些步骤工作正常,但intro.js无法正确识别这些步骤中提供的元素。我尝试过用document.getElementById()和document.querySelector()来定义元素,.Nothing似乎还行得通。还有别的办法吗?
import React,{useState} from 'react'
import { Steps, Hints } from "intro.js-react";
import "intro.js/introjs.css"
import "intro.js/themes/introjs-nassim.css";
const AppIntro = () =>{
const [stepsEnabled, setStepsEnabled] = useState(false)
const [initialStep, setInitialStep] = useState(0)
const [steps, setSteps] = useState([
{
intro:"Welcome to our application",
position: 'top'
},
{
element:document.getElementById('.card'),
intro: 'This is the second step',
position: 'left'
},
{
element: document.querySelector('.tableRow'),
intro:'This is the third step',
position: 'top'
}
])
const onExit = () =>{
setStepsEnabled(false);
}
const startIntro=()=>{
setStepsEnabled(true)
}
return(
<div>
<button onClick={()=>startIntro()}>Click me</button>
<Steps
enabled={stepsEnabled}
steps={steps}
initialStep={initialStep}
onExit={onExit}
options=
{{
tooltipClass: 'customTooltip',
showProgress: true,
showStepNumbers: true,
showBullets: false,
exitOnOverlayClick: false,
doneLabel: "Done",
nextLabel: "Next",
hideNext: false,
}}
/>
</div>
)}导出默认AppIntro
这是我的组件
发布于 2021-09-15 16:28:31
你需要更换
{
element:document.getElementById('.card'),
intro: 'This is the second step',
position: 'left'
},
{
element: document.querySelector('.tableRow'),
intro:'This is the third step',
position: 'top'
}使用
{
element: '.card',
intro: 'This is the second step',
position: 'left'
},
{
element: '.tableRow',
intro:'This is the third step',
position: 'top'
}这将使步骤附加到具有.card和.tableRow类的元素。如果您希望使用ID来标识要附加到的元素,可以将'.card‘替换为'# card’,以便使用card的id附加到该元素。
https://stackoverflow.com/questions/66135118
复制相似问题