我制作了一个组合,并且我想通过添加流行的自动输入效果,将我的名字更改为各种其他字符串,如auto堆栈、前端、..etc,在我的名字上应用动画。
我找到了创建动画类型效果的这轻量级库,但我不知道如何将脚本正确地实现到我的jsx文件中。我在下面试过了,但是我根本无法渲染动画。
到目前为止,这是我的尝试:
var AutoTyping = function (e) { var t = {}; function r(n) { if (t[n])
//...
const exampleText = ['Fullstack.', 'FrontEnd', 'BackEnd', 'Designer'];
const exampleTyping = new AutoTyping('#text', exampleText, {
typeSpeed: 50,
deleteSpeed: 50,
waitBeforeDelete: 2000,
waitBetweenWords: 500,
});
exampleTyping.start()import { autotyping } from "./../../autotyping";
const About= () => {
return (
<p id="text" class="text-red-500">
<autotyping>
<script src="./../../autotyping" type="text/javascript"/>
</autotyping>
</p>
)}发布于 2022-08-12 11:37:18
您必须在useEffect中运行任何命令式代码
组件
const AutoTyping = () => {
useEffect(() => {
const exampleText = ['Fullstack.', 'FrontEnd', 'BackEnd', 'Designer'];
const exampleTyping = new AutoTyping('#text', exampleText, {
typeSpeed: 50,
deleteSpeed: 50,
waitBeforeDelete: 2000,
waitBetweenWords: 500,
});
exampleTyping.start()
})
}用法
const About = () => {
return (
<p id="text" class="text-red-500">
<AutoTyping />
</p>
)
}要加载组件,请将脚本标记添加到HTML中,不要将其嵌入到jsx中
https://stackoverflow.com/questions/73332939
复制相似问题